首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

两个表查询,该怎么处理

2012-12-31 
两个表查询同一数据库内有两个表A和表B,A和B具有相同的字段和结构,只是存储的数据不同。现在程序要求各查询

两个表查询
同一数据库内有两个表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 这些列不明确。那我该怎么写才对呢?


[解决办法]

select id,title,username,time,class from table20 where id=1  
union all
select id,title,username,time,class from table19 where id=1

热点排行