Results 1 to 2 of 2
Thread: MySQL Query Question
- 07-16-2012, 11:13 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 27
- Rep Power
- 0
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
- 07-16-2012, 02:17 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: MySQL Query Question
Your query and table definitions don't match.
EmployeeAssignment does not have an empId.
Anyway, assuming that's just a typo, you want to use outer joins.
Inner join the EA and CS tables together, then OUTER JOIN the employee table.
You'll then need to dig into the MySQL docs to find how you can do DECODE or CASE statements to turn the NULLs into 'N/A'.Please do not ask for code as refusal often offends.
Similar Threads
-
Eclipse MySQL query
By kenmat514 in forum EclipseReplies: 2Last Post: 06-23-2011, 10:39 PM -
MySQl query taking too much time
By jessie in forum JDBCReplies: 16Last Post: 11-11-2010, 01:09 PM -
Query MySQL
By boss in forum Advanced JavaReplies: 3Last Post: 01-04-2010, 09:36 AM -
Query MySQL
By boss in forum Advanced JavaReplies: 3Last Post: 01-04-2010, 09:35 AM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 01:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks