帮忙简化一句查询语句吧?对高手来说很简单的!谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:48:00
SELECT top 1 * from News order by id union select top 1 * from Scenes order by id union select top 1 * from Links order by id union select top 1 * from Amenity order by id
要查到每个表的最后一行,也就是将每个数据表的最后一项提出合并成一个数据集rs,然后调用。
SELECT top 1 * from News order by id desc union select * from( select top 1 * from Scenes order by id desc) union select * from( select top 1 * from Links order by id desc) union select * from( select top 1 * from Amenity order by id desc)
是这样吗?
如果是怎么简化一下啊,太长了

你用的是union,已经剔除重复记录,简化也只能吧order by 去掉,只保留数据结果最多的那张表上的order

将前面的order by id去掉,只保留一个。

SELECT top 1 * from News order union select top 1 * from Scenes union select top 1 * from Links union select top 1 * from Amenity order by id desc
查询结果不包含重复值;
SELECT top 1 * from News order union all select top 1 * from Scenes union all select top 1 * from Links union all select top 1 * from Amenity order by id desc
查询所有值,包括重复值