Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


Need help with an SQL Statement

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Microsoft SQL Server
Author Message
Eric
Idea Hamster


Joined: 21 Oct 2004
Posts: 679
Location: Bangor, Maine

PostPosted: Thu May 26, 2005 9:39 am    Post subject: Need help with an SQL Statement Reply with quote

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

PostPosted: Thu May 26, 2005 10:25 am    Post subject: Reply with quote

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

PostPosted: Thu May 26, 2005 10:47 am    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Microsoft SQL Server All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group