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

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-04-09 : 11:17:58
I have a table that has the following fields
Account_number,account_cd.. the account_CD can be E or I and an account_number can be assigned an E or an I per row

Example


Account_number Account_cd
1234 I
1234 E
3456 I
6777 I
6777 E
7888 E
8999 I

So I want to only choose the account_numbers that have account_CD of E and do not have an Account_cd of I. so in the example above I only want to select account 7888 as that is the only Account_number that has an E and does not have an I

robvolk
Most Valuable Yak

15732 Posts

Posted - 2013-04-09 : 11:20:13
SELECT Account_number FROM myTable GROUP BY Account_number HAVING MAX(Account_cd)='E'
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 2013-04-09 : 11:48:02
Thank you it worked perfect...
Go to Top of Page
   

- Advertisement -