SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 New Topic  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

15720 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000