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 |
|
dejan88
Starting Member
7 Posts |
Posted - 2012-03-07 : 08:13:49
|
| I have two tables:T1: ID STATUS1 NEW2 OPEN3 PENDINGT2:ID VALUE DESCRIPTION1 2 A11 20 A22 3 B12 30 B2 I would like to join this two tables with left outer join but from the second table to get only DESCRIPTION for max VALUE for that ID.Result Table:ID DESCRIPTION1 A22 B23 nullMy sql query is:SELECT T1.ID, T2.DESCRIPTION FROM T1 LEFT OUTER JOIN T2ON T1.ID=T2.ID WHERE T2.VALUE= (SELECT MAX(VALUE) FROM T2WHERE T2.ID=T1.ID) but I do not have ID 3 in my result which I do want although I did Left Outer Join. So what do I miss?Thanks |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-03-07 : 08:35:02
|
try to add to the WHERE clause:OR (T2.ID IS NULL) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
dejan88
Starting Member
7 Posts |
Posted - 2012-03-07 : 09:00:35
|
| Thanks |
 |
|
|
|
|
|