Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

153 Posts

Posted - 04/09/2013 :  11:17:58  Show Profile  Reply with Quote
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


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

Most Valuable Yak

15732 Posts

Posted - 04/09/2013 :  11:20:13  Show Profile  Visit robvolk's Homepage  Reply with Quote
SELECT Account_number FROM myTable GROUP BY Account_number HAVING MAX(Account_cd)='E'
Go to Top of Page

Posting Yak Master

153 Posts

Posted - 04/09/2013 :  11:48:02  Show Profile  Reply with Quote
Thank you it worked perfect...
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000