当前位置: 代码迷 >> Sql Server >> 两个表查询解决思路
  详细解决方案

两个表查询解决思路

热度:98   发布时间:2016-04-27 11:13:06.0
两个表查询
同一数据库内有两个表A和表B,A和B具有相同的字段和结构,只是存储的数据不同。现在程序要求各查询这两个表的首行,然后共同显示在一个datalist中。也就是希望得到的结果是这连个连接之和:
 select id,title,username,time,class from table20 where id=1 
 and
 select id,title,username,time,class from table19 where id=1


我想这样写来着:
select id,title,username,time,class from table20,table19 where table20.id=1 and table19.id=1

结果提示 id,title,username,time,class 这些列不明确。那我该怎么写才对呢?



------解决方案--------------------
SQL code
select id,title,username,time,class from table20 where id=1  union allselect id,title,username,time,class from table19 where id=1
  相关解决方案