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

Sorting a Field

Status
Not open for further replies.

118600

Vendor
Feb 15, 2005
36
0
0
DE



Hi Guys,

I have a problem, for you guys sure not a problem but for its now a big problem.

There are 7 Fields in a table of a linked database. I have to sort them according to EmployNr

such like

EmpNr EmpName EmpAdd etc.....
23
23
23
23
24
24
24
25
25
25
52
52
52
75
75
75
75
76

The related information in other fields is same according to each EmpNr.
I am trying to sort it out this table such like..... as the same EmpNr is
appearing with same related fields information.So It should come just once with
related fields

like

EmpNr EmpName EmpAdd etc.......
23
24
25
52
75
76


Also, i cannt assign it as Primary key.I have tried to solve it by Group By but in vain. I have to use here some extra queries..........

Anyone can help me ? I will be thankfull
 
if all the information in the other fields is the same, you can add DISTINCT to your SELECT statement and one record will be returned for each distinct record you are selecting.

Code:
SELECT EmpNr, EmpName, EmpAdd FROM Employees

Results:
EmpNr     EmpName    EmpAdd
23        Doe, John  123 Main St.
23        Doe John   123 Main St
23        Doe, John  123 Main St.
23        Doe john   123 Main
The first and third results match EXACTLY, so if you run the same statement with the Distinct keyword, only one row will be gone because there are differences:

Code:
SELECT [b]Distinct[/b] EmpNr, EmpName, EmpAdd FROM Employees

Results:
EmpNr     EmpName    EmpAdd
23        Doe, John  123 Main St.
23        Doe John   123 Main St
23        Doe john   123 Main

Leslie
 
And if the differences are negligible for you:
SELECT EmpNr, Max(EmpName) AS Emp_name, Max(EmpAdd) As Emp_Add
FROM yourTable
GROUP BY EmpNr

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top