另一个左连接查询

时间:2012-11-16 21:15:01

标签: sql left-join inner-join

我有表LS_CLIENT_TRANS

CODE_CLIENT  OTHER_CLIENT
4444         4444
4444         8585

和表格CLIENT

CODE_CLIENT  ADRESS
4444         RR
8585         GG

我怎么能得到:

  CODE_CLIENT  OTHER_CLIENT  ADRESS
    4444         4444         RR
    4444         8585         GG

当我使用

 SELECT *
   FROM LS_CLIENT_TRANS
   LEFT JOIN CLIENT ON LS_CLIENT_TRANS.CODE_CLIENT = CLIENT.CODE_CLIENT
我得到了:

CODE_CLIENT  OTHER_CLIENT  ADRESS
    4444         4444         RR
    4444         8585         RR

3 个答案:

答案 0 :(得分:1)

SELECT *
FROM LS_CLIENT_TRANS
LEFT JOIN CLIENT ON LS_CLIENT_TRANS.OTHER_CLIENT = CLIENT.CODE_CLIENT

答案 1 :(得分:0)

JOIN上的{p> ON l.OTHER_CLIENT = c.CODE_CLIENT就像这样:

SELECT
  l.CODE_CLIENT,
  l.OTHER_CLIENT, 
  c.Adress
FROM LS_CLIENT_TRANS l
LEFT JOIN CLIENT c ON l.OTHER_CLIENT = c.CODE_CLIENT

SQL Fiddle Demo

答案 2 :(得分:0)

SELECT t.CODE_CLIENT, t.OTHER_CLIENT, c.ADDRESS
FROM LS_CLIENT_TRANS t 
JOIN CLIENT c ON t.OTHER_CLIENT = c.CODE_CLIENT