多表查询,数据库达人来。

来源:百度知道 编辑:UC知道 时间:2024/06/10 22:39:55
select top 6 c.* from (select id,title from info14 union all select id,title from info15 union all select id,title from info16 union all select id,title from info17 union all select id,title from info18) c order by c.time desc

查询出这5个表的头6条内容,按时间排序,让我输入 c.time值
这个查询功能是帮助求来的,不懂,关于‘c’是什么?谁能再给解释下。
所有表中都有 time字段 我想按时间倒序该怎么写?

c是作为 select id,title from info14 union all select id,title from info15 union all select id,title from info16 union all select id,title from info17 union all select id,title from info18
这个查询结果的别名

这里的C应该是数据库中的一个表名吧。
order by c.time desc即是实现按C表中的TIME字段排序。
top 6 c.* 即是实现显示C表中符合条件的前六条记录的所有字段.

(select id,title from info14 union all select id,title from info15 union all select id,title from info16 union all select id,title from info17 union all select id,title from info18) c
看这段代码,也就是给()内的SQL语句查询的结果起了个别名 c。

C是临时表的别名

select id,title from info14 union all select id,title from info15 union all select id,title from info16 union all select id,title from info17 union all select id,title from info18
这个查询结果作为一个结果集,这个结果集的名字是c。
其实可以这样简单的看:

select top 6 c.* from c
order by c.time desc

order by c.time desc这条语句就是按time倒序排序的。