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

sql语句查两张表,两张表里有相同的列 ,这俩列怎么区别是那个表的
select a.ssgdgx , a.gh, a.dj, a.xh, b.xh, b.tggg, b.yt, b.jgdate, b.nbid from
table1 a, table2 b where a.dgid = b.id and ssgdgx like '%X0001455@%'
  
这是两张表 table1 和表 table2
 根据条件查出内容后 有两列是 xh , 想知道用什么方法可以将这俩列区分开


------解决方案--------------------
--给查出来的字段加别名:
select a.ssgdgx , a.gh, a.dj, 
a.xh as a_xh, b.xh as b_xh, b.tggg, b.yt, b.jgdate, b.nbid from
table1 a, table2 b where a.dgid = b.id and ssgdgx like '%X0001455@%'