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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select with rule

Author  Topic 

Tye
Starting Member

1 Post

Posted - 2009-06-04 : 19:42:53
I'm not sure even what to title this.

At a very basic level, here is my data

Library Item
------- ----
Library1 ItemA
Library2 ItemA
Library3 ItemA
Library2 ItemB
Library3 ItemB

Library3 exists for every time in the table and I only want to select Library3/Item pair if Library1 and Library2 don't exist for the item.

If Library2 exists and Library1 does not, I want to select the Library2/Item pair and ignore or not select in my results the Library3/Item pair

and finally if Library1 exists on the item I want to select only the Library1/Item pair and ignore the Library2 and Library3 pairs.

I'm struggling to figure out where to begin. CASE? IF ELSE?

Can anybody help peel this back?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-05 : 13:09:51
[code]
SELECT MIN(Library),Item
GROUP BY Item
[/code]
Go to Top of Page
   

- Advertisement -