Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
abyss
Starting Member
1 Post |
Posted - 2004-12-16 : 03:29:06
|
| need help on biuding a query...i.e. there are 2 tables:================== ===========================ID name memo ID mail url================== ===========================5 me nomemo 92 trash@mail.com www.t.co20 you 1k no mail www.12.lt92 who text101 any memo1k manyhow should the query look to obtain rezult containing all table1 fields + all table2 fields, even if ID2<>ID1 (the field must be blanc)expecting 4 result.... :================================================ID name memo mail url=================================================5 me nomemo 20 you 92 who text trash@mail.com www.t.co101 any memo no mail www.12.lt1k many |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2004-12-16 : 13:22:40
|
| If I understand the requirements correctly, you want:1) Every row of table12) If there is a matching row in table2, use that data also3) If there is NOT a matching row in table2, use blanks for table2's columnsselect t1.ID, t1.Name, t1.Memo, coalesce(t2.Mail, ''), coalesce(t2.url, '')from table1 t1LEFT OUTER JOIN table2 t2on t1.ID = t2.IDYou can look up JOIN in books online (BOL) for a discussion of what the INNER, OUTER and CROSS JOINS are and how to use them.HTH=================================================================Happy Holidays! |
 |
|
|
|
|
|