Results 1 to 3 of 3

Thread: query problem

  1. #1
    Join Date
    Nov 2011
    Posts
    5

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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;
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2011
    Posts
    5
    thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •