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

问大家一个语句,在线等
表A
a1      a2
10       1
11       1
12       1
20       2
21       2
22       2   等等
表B
b1      b2
1       one
2       two
10      ten
11      eleven
12      twelve
20      twenty
21      twenty one
22      twenty two
都是字符型,a1,a2都与b1有关联,现在要输出
两列c1    c2,显示的是a1,a2对应的b2字段。

select distinct c.b2,b.b2 
from (select a.a2,b.b2 from a,b where a.a1=b.b1) c,b
where c.a2=b.b1;

这是一种方法,我洗完从select  这里做好处理  from 。。。 left join 。。。(这里只写连接条件)
sql

------解决方案--------------------
/*
b2               b2
------------- ---------
ten              one
eleven           one
twelve           one
twenty           two
twenty one       two
twenty two       two

(6 行受影响)
*/