Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Unanswered: MySQL Query Question

    i have three tables

    Employee
    empId int pk
    empname varchar

    customersite
    empid int pk fk
    custid int pk fk
    startdate date pk
    enddate date

    employeeassignment
    custid int pk
    sitename varchar

    my question is

    How to show the name of all our employees with the customer name of those who are on customer sites today. For those who are not, show 'N/A' for the name and address.

    i have so far

    SELECT
    e.EmpName,
    cs.SiteName
    FROM
    EmployeeAssignment ea
    INNER JOIN
    Employee e
    ON
    e.EmpId = ea.EmpId
    INNER JOIN
    CustomerSite cs
    ON
    cs.CustId = ea.CustId

    which give me all employee at work today, with their name and the site.

    any help you be very appreciated thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by dcalladi1991 View Post
    Code:
    FROM
        EmployeeAssignment ea
    INNER JOIN
        Employee e
    ON
        e.EmpId = ea.EmpId
    that's not going to work, because your EmployeeAssignment doesn't have an Empid column

    by the way, are you using mysql or microsoft sql server? because you posted in the sql server forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2012
    Posts
    213
    Do you by any chance changed the names of tables customersite and employeeassignment?
    Because the SQL statement you posted does not match the structure of tables.
    And I have not found the customer_name or customer_address columns in any of the tables.

Posting Permissions

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