| Author |
Message |
Eric Idea Hamster
Joined: 21 Oct 2004 Posts: 679 Location: Bangor, Maine
|
Posted: Thu May 26, 2005 9:39 am Post subject: Need help with an SQL Statement |
|
|
Ok. I have two tables.
tblEmployee
tblTelephone
Telephone relates to the Employee. There can be multiple telephone numbers per employee.
Here is what I need:
Every employee record, and the FIRST telephone number for that employee.
My brain isn't working well this morning... I think it's the rain. |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Thu May 26, 2005 10:25 am Post subject: |
|
|
When you say first telephone number do you mean the first one that comes up in the database? First one alphabetically? Or do you have a priority on them?
Just to assume priority
| Code: |
SELECT e.Name, t.PhoneNumber, MIN(t.Priority)
FROM tblEmployee e INNER JOIN tblTelephone t ON e.ID = t.empID
GROUP BY e.Name, t.PhoneNumber
ORDER BY e.Name -- assuming this is for a phone list |
|
|
| Back to top |
|
 |
Eric Idea Hamster
Joined: 21 Oct 2004 Posts: 679 Location: Bangor, Maine
|
Posted: Thu May 26, 2005 10:47 am Post subject: |
|
|
Thanx Josh! I knew someone here would have an answer. I'll put that to work.
I have a priority on the fields, so that will work. |
|
| Back to top |
|
 |
|