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 |
|
olibara
Yak Posting Veteran
94 Posts |
Posted - 2012-01-05 : 05:32:38
|
| HelloI have a table with 3 columnBoxIDDateCheckedMany rows can have the same BoxIDChecked can have value 0 o 1I need to sellect All distinct BoxID having Date NOT NULL AND WITH ALL Checked value = 1What will be the best way to do that ?Thanks for any help |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-05 : 05:57:27
|
select distinct BoxIDfrom MyTable t1where Date is not nulland Checked = 1and not exists(select * from MyTable t2 where t2.BoxID = t1.BoxID and checked = 0) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
olibara
Yak Posting Veteran
94 Posts |
Posted - 2012-01-05 : 06:55:02
|
| Thank you SQLFredYes your solution works but I'm not sure it is very efficientI had the Idea to use a PARTITION OVER but I'm not sure about it either |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-01-05 : 07:05:10
|
[code]select BoxIDfrom MyTablewhere date is not nullgroup by BoxIDhaving min(checked) = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-05 : 07:14:28
|
quote: Originally posted by khtan
select BoxIDfrom MyTablewhere date is not nullgroup by BoxIDhaving min(checked) = 1 KH[spoiler]Time is always against us[/spoiler]
That's fine  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
olibara
Yak Posting Veteran
94 Posts |
Posted - 2012-01-05 : 09:11:11
|
| yes nice thank you ! |
 |
|
|
|
|
|