我正在尝试从3张桌子中获取最新的5个标题,我想在我的陈述中可能会出错。
这是我的陈述
SELECT * FROM news N, blog B, comments C WHERE active='1' ASC LIMIT 5
答案 0 :(得分:0)
在FROM
之后,您只能设置1个结果来自的表格。此外,如果您使用关键字ASC
,您还应该说出order by
尝试的字段:
SELECT * FROM news WHERE active='1' order by 'fieldnew' ASC
UNION ALL
(SELECT * FROM blog WHERE active='1' order by 'fieldblog' ASC)
UNION ALL
(SELECT * FROM comments WHERE active='1' order by 'fieldcommnet' ASC)
答案 1 :(得分:0)
您需要在提供的三个表上进行连接!
在sql-server中:
select top 5 * from
(
select * from News N inner join blog B on N.id=B.id inner join comments C on C.id=N.id
)x
order <something>