var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: SQL Join and Sub Query problem
I'm having problems writing the SQL to Join a query with a table to show all employees for a particular company.
I have the following query so far:
SELECT Country, Region, Company, FullName, EmpNo, LRTime_Stamp, Total, LRSupervisor_EmpNo, LRSupervisor_Name
WHERE (Country ='England') AND (Region = 'Yorkshire') AND (Company = 'MMM') AND (Type = 'Business')
GROUP BY Country, Region, Company, FullName, LRTime_Stamp, LRSupervisor_EmpNo, LRSupervisor_Name;
I then want to join this to a table called 'Employees' and show all of the records in the 'Employees' table regardless of whether they are in the 'qSel_All_Data_2' query or not.
The 'Employees' table has the following fields:
And I would want to join on Country, Region, Company, Empno.
At the moment when I try and join it only returns the records that satisfy the WHERE criteria. Do I need a subquery of some kind???
Any help would be appreciated.
You need an OUTER JOIN:
SELECT e.id, ..., q.xxx, ...
FROM employees e
LEFT OUTER JOIN qSel_All_Data_2 q
ON q.country = e.country AND ...
Also - your group by clause appears a little superfluous
ur codings are working excelent.