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 |
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2008-02-01 : 14:38:26
|
| I have two tables:Table1------item type colour date1 A Red 24/03/20072 J Blue 27/03/20073 A Black 27/03/2007 Table2------code id description1 A Pending1 J Not listed3 J ReturnedI wish to JOIN Table1.type to Table2.description when Table1.item = Table2.code AND Table1.type = Table2.idto give the result:item type colour date1 Pending Red 24/03/20072 Blue 27/03/20073 Black 27/03/2007How can I do this please? |
|
|
tprupsis
Yak Posting Veteran
88 Posts |
Posted - 2008-02-01 : 16:00:06
|
| It looks like you need an outer join where you want all records from Table1 and the description from Table2 if it's there. Am I understandin that correctly?If so, try this:SELECT T1.item, T2.description, T1.colour, T1.dateFROM Table1 T1 LEFT OUTER JOIN Table2 T2 ON T1.item = T2.code AND T1.type = T2.id |
 |
|
|
|
|
|