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

selecting only one row of data

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi.

I have 2 fields employee_number and department

Some employees have more than one department but I only want to select one.
When I have 20000 records, how do I only select one of each employee?
 
SELECT * FROM TABLE
WHERE DEPARTMENT=(dept name or number here)
Above will pull all employee records with dept entered.

If you want to pull up a certain employee:
SELECT * FROM TABLE
WHERE EMPLOYEE_NUMBER=(number) AND DEPARTMENT=(dept)

Hope this helps.
TNN, Tom
TNPAYROLL@AOL.COM

TOM
 
Hi,
It would work if I wanted to just get one department. I acutally need to get all emplyees and only one department, no matter what department, as long as its one of them.

Thanks,
Ty
 
You could do a 'group by' on employee number and take min() or max() department.

If this is a frequent operation then doing a group by on 20k records may be a bit slow. It may be worth having a 'main department' flag which you could then select on. My Home -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top