开发者

how to check the condition in sql server?

Table 1

   slitem    firstname    lastname
    1         aaa           bbb

Table 2

slitem    firstname    lastname
 1         null           null
 2          null        null

Result :

slitem    firstname    lastname
    1         aaa       开发者_如何学C    bbb
    2        null          null

i want to join this two table....

help me


SELECT COALESCE(t1.slitem, t2.slitem) AS slitem, 
       COALESCE(t1.firstname, t2.firstname) AS firstname, 
       COALESCE(t1.lastname, t2.lastname) AS lastname
FROM      table1 t1 
FULL JOIN table2 t2 ON t1.slitem = t2.slitem

(Edit because OMG Ponies edited my FULL JOIN into a LEFT JOIN... which was not my intention!)


It sounds like you are looking for a left outer join:

SELECT * FROM Table1 LEFT JOIN Table2 ON table2.slitem = Table1.slitem WHERE 1=1


You want a left join, just like the other answers said...but considering this is a rather basic thing to know when working SQL, you might want to read up a bit on it. Here's a good place to start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜