tableone: id | userid | date | photo | caption | visible
tabletwo: id | userid | date | text | gender | notes
列が異なる 2 つのテーブルがあります。単一のクエリを使用して両方から行を選択したいのですが、日付 (タイムスタンプ) とユーザー ID を使用してこれを行います。それらを一緒に結合することは可能ですか?
SELECT id, photo, caption, visible
FROM `tableone`
WHERE `userid` = $user->id AND `date` = '$d'
ORDER BY date desc
SELECT id, text, gender, notes
FROM `tabletwo`
WHERE `userid` = $user->id AND `date` = '$d'
ORDER BY date desc
LIMIT 1
編集: 望ましい出力:
(
[id] => 3
[photo] => 1
[caption] => Sample text
[visible] => 1
[text] =>
[gender] =>
[notes] =>
)
(
[id] => 23
[photo] => 1
[caption] => More sample text
[visible] =>
[text] =>
[gender] =>
[notes] =>
)
(
[id] => 1
[photo] =>
[caption] =>
[visible] =>
[text] => Blah jaspidj
[gender] => 2
[notes] => Sample Text
)