PDA

View Full Version : Merging Tables



gibbo1715
10-31-2005, 07:03 AM
Any Takers here please as I need to know if this is possible?

http://www.ozgrid.com/forum/showthread.php?t=41744


Cheers

Gibbo

xCav8r
10-31-2005, 09:02 AM
Use a UNION query just as Norie suggested.

gibbo1715
10-31-2005, 09:17 AM
Use a UNION query just as Norie suggested.


Any chance of an example query please then i ll amend it to my needs

cheers

gibbo

geekgirlau
11-01-2005, 12:56 AM
You can either do a simple union of two sub queries

SELECT *
FROM sqsel_Inbound_Employee
UNION SELECT *
FROM sqsel_Inbound_General

or do the full version

SELECT CDate(Format([dtm_Inbound],"d-mmm-yyyy")) AS CallDate, [txt_Emp_FirstName] & " " &
[txt_Emp_Surname] AS Emp, tlst_Role.txt_Role
AS Area, Count(tbl_Call_Inbound.lng_Inbound_Staff) AS Calls
FROM tlst_Role RIGHT JOIN (tbl_Employee INNER JOIN tbl_Call_Inbound ON tbl_Employee.aut_Emp_ID =
tbl_Call_Inbound.lng_Inbound_Staff) ON tlst_Role.aut_Role = tbl_Employee.lng_Emp_Role
GROUP BY CDate(Format([dtm_Inbound],"d-mmm-yyyy")), [txt_Emp_FirstName] & " " & [txt_Emp_Surname],
tlst_Role.txt_Role

UNION SELECT CDate(Format([dtm_Inbound],"d-mmm-yyyy")) AS CallDate, "" AS Emp, tlst_Inbound.txt_In
AS Area, Count(tbl_Call_Inbound.lng_Inbound_Staff) AS Calls
FROM tbl_Call_Inbound INNER JOIN tlst_Inbound ON tbl_Call_Inbound.lng_Inbound_Staff =
tlst_Inbound.lng_In_ID
GROUP BY CDate(Format([dtm_Inbound],"d-mmm-yyyy")), "", tlst_Inbound.txt_In

Either way will give you the same results, although personally I find it easier to build and test the queries separately rather then combine them in the union query from the start. Just remember that the 2 (or more) queries must have the same number of fields.