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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I select all fields but no duplicates?

Status
Not open for further replies.

Ferlin

Programmer
Jan 18, 2001
71
US
I have an employee database that has year to date information in it, it has a record for each payroll run through the year, which means multiple records for each employee.

I need help with an sql statement that will give me all the fields in the table, but only one record per social security number.

When I try to use the distinct(social_security_number) on the select it ONLY returns the social_security_number field, and if I try to select distinct with a comma and the *, it returns everyone of the records, like it is trying to find distinct records on ALL the fields combined.

Please help, I have spent HOURS and multiple select statements, only to lead to frustration.

Thanks in advance.

Ferlin.
 
Ferlin, what you have learned about Distinct is accurate. As you add more fields the rows are considered distinct if any one of the columns is different.
The question becomes what rows do you want returned? The most recent based upon a pay date? Is there a unique key in this table?
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top