Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query problem 1

Status
Not open for further replies.

monnet

IS-IT--Management
Feb 5, 2007
9
US
Ok so here is a very simplified version of the table I am using:

SSN ADDRESS FundCompany
1. 777-77-7777 1 Smith St Company A
2. 777-77-7777 1 Smith St Company B
3. 777-77-7777 1 Smith St Company B
4. 888-88-8888 2 Water St Company A
5. 888-88-8888 2 Water St Company D


I need a query that would that would pull the SSN and the Address BUT only for the first record of each SSN.

So the result of this query would be:

SSN ADDRESS
1. 777-77-7777 1 Smith St
2. 888-88-8888 2 Water St

What would the WHERE clause for this kind of SQL statement be?

Thanks everyone.

BM
 
You may try simply this:
SELECT DISTINCT SSN, ADDRESS
FROM yourTable

or this:
SELECT SSN, ADDRESS
FROM yourTable
GROUP BY SSN, ADDRESS

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You might want to check out the [tt]Top N [Percent][/tt] clause for a select query; it lets you specify how many (either an absolute count or a percentage) records you want. If your sample records were anything like the real data, it looks like you could specify the top 1 for each SSN, if the data's really sorted by the FundCompany (& the combination of SSN & FundCompany is unique; otherwise, it'll have to be some other field).

Hope that helps...

—RJF

"Res ipsa loquitur, sed quid in infernos dicet?
 
Thanks for the Help guys, the DISTINCT command worked prefectly!

BM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top