If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-29-11, 21:56
donan donan is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
query problem

Well hi there

I have this piece of query

Code:
SELECT EmployeeID, count(EmployeeID) As Count
FROM Projects
Group By EmployeeID;
Briefly, the above query outputs a table in which the ID's of employees are displayed along with the amount of projects they are working on

what I want to do is:

add another line(s) in the query so it adds a column from a different table (in this case, I want the employee's full name to be shown next to the employee id and project amount, but without creating that column in the 'Projects' table - 'employee name' exists in 'employee' table)

what I tried is:

Code:
SELECT EmployeeID, count(EmployeeID) As Count
FROM Projects
AND SELECT EmployeeName From Employee
Group By EmployeeID;
But obviously mysql doesnt accept this kind of queries

I hope you can help me

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 11-29-11, 22:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
what you're looking for is called a join
Code:
SELECT Projects.EmployeeID
     , Employee.EmployeeName
     , COUNT(*) As Count
  FROM Projects
INNER
  JOIN Employee
    ON Employee.EmployeeID = Projects.EmployeeID
GROUP 
    BY Projects.EmployeeID;
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-30-11, 07:04
donan donan is offline
Registered User
 
Join Date: Nov 2011
Posts: 5
thank you!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On