日期:2014-05-17  浏览次数:20417 次

两个表查询
同一数据库内有两个表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