加别名:select [id] from (select TP_Title as Title,Type=2, tp_id as [id] from TB_Resource_TeachingPlan UNION ALL select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter)T
解决方案 »
- 如何查询一个字段内容包含另一个字段内容,急,在线等
- 存储过程求助
- 求一最优SQL,在线等...
- 试图的一个小问题,一解决明天早晨来就结帖啊!!!
- 请助SQL批量修改数据的问题?
- 求助,急,远程sql server 更改端口号,就是连不上。
- 给分! 初学者,有点难,SQL安装问题,请大侠赐教
- [email protected] 密码299981 有一个数据库,数据库中的存储过程被加密了,解密代码解的有问题,欢迎大家挑战
- 数据库还原时提示:数据库正在使用,未能获得对数据库的排它访问权,怎么改代码呢?谢谢!
- 关于sql的问题,紧急啊,解决不了就得加班啊
- 问个sum group by 的查询语句
- 如何删除表中的重复记录,只剩下一条?
select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter)a
select a.[id] from
(select TP_Title as Title,Type=2, tp_id as [id] from TB_Resource_TeachingPlan
UNION ALL select Mat_Title as Title,Type=3, mat_id as [id] from TB_Resource_Matter) A
或者,这样写行吗.
select
tp_id as [id] from TB_Resource_TeachingPlan
UNION ALL
select
mat_id as [id] from TB_Resource_Matter[id]也可以求出来!
select tp_id as [id] from TB_Resource_TeachingPlan
UNION ALL select mat_id as [id] from TB_Resource_Matter
--因为用union all,重复的也是出来,而且顺序不变,而且第二个mat_id 不一定要别名,默认和第一个select的一样