tableone: id | userid | date | photo | caption | visible
tabletwo: id | userid | date | text | gender | notes
我有两个不同列的表。我想使用单个查询从两者中选择行,我会使用日期(时间戳)和用户 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
)