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 |
cognos79
Posting Yak Master
241 Posts |
Posted - 2007-12-13 : 16:02:38
|
I want to do a group by id and retrieve the records where atleast one of the records returned by that group has null value in last name.Id Last Name 1 paul1 null1 mike2 carol2 jenExpected Result:1 paul1 null1 mike. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-13 : 16:05:32
|
Something like this should work:SELECT Id, NameFROM YourTable t1WHERE EXISTS (SELECT * FROM YourTable t2 WHERE t1.Id = t2.Id AND t2.Name IS NULL)GROUP BY IdTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-13 : 19:28:41
|
[code]SELECT Id, max(Name)FROM YourTable t1WHERE EXISTS (SELECT * FROM YourTable t2 WHERE t1.Id = t2.Id AND t2.Name IS NULL)GROUP BY Id[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-14 : 03:44:40
|
quote: Originally posted by khtan
SELECT Id, max(Name)FROM YourTable t1WHERE EXISTS (SELECT * FROM YourTable t2 WHERE t1.Id = t2.Id AND t2.Name IS NULL)GROUP BY Id KH[spoiler]Time is always against us[/spoiler]
SELECT Id, NameFROM YourTable t1WHERE EXISTS (SELECT * FROM YourTable t2 WHERE t1.Id = t2.Id AND t2.Name IS NULL)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|