【发布时间】:2013-01-19 19:38:07
【问题描述】:
我有以下三个表,我想通过userid 从它们中提取数据,这是赋予它们关系的一个关键字段。我还想按timestamp 的顺序提取数据,下面是表架构示例,以及我所拥有的联合查询不起作用。
Table1: userid, event_id, event_name, timestamp
Table2: id_user, comment, timestamp
Table3: user_id, photo, timestamp
$result5 = mysql_query
("(SELECT event_name, timestamp FROM table1 WHERE userid = '25')
UNION ALL
(SELECT comment,timestamp FROM table2 WHERE id_user = '25')
UNION ALL
(SELECT photo,timestamp FROM table3 WHERE user_id ='25')
ORDER BY timestamp")
or die(mysql_error());
【问题讨论】:
-
所以你想“拉”那个用户的所有 event_names,他所有的 cmets 和他的所有照片?如果这 3 列(
event_name、comment、photo)兼容(例如,它们都是CHAR或VARCHAR),是的,您的查询似乎没问题。你能澄清一下“它不工作”的原因吗?