UNION Query syntax Issue (1 Viewer)

Buxtona

Registered User.
Local time
Today, 13:24
Joined
Jun 20, 2019
Messages
17
Hi

Im trying to combine 3 tables into 1 using a union query. the 3 tables have the same fields/Data types but i keep getting this UNION.jpg

Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:24
Joined
May 7, 2009
Messages
19,227
is serialDate string?
 

Buxtona

Registered User.
Local time
Today, 13:24
Joined
Jun 20, 2019
Messages
17
No its a numeric field
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:24
Joined
Sep 21, 2011
Messages
14,217
Try using brackets?

I *think* the A is from the start of the AND ?
 

Buxtona

Registered User.
Local time
Today, 13:24
Joined
Jun 20, 2019
Messages
17
Tried it with these brackets:

SELECT wj_attendance.ShopID
FROM wj_attendance
WHERE (wj_attendance.EmployeeID=3372) AND (wj_attendance.SerialDate Between 20160101 And 20191016)
UNION
SELECT wj_attendance2017.ShopiD
FROM wj_attendance2017
WHERE (wj_attendance2017.EmployeeID=3372) AND (wj_attendance2017.SerialDate Between 20160101 And 20191016)
UNION
SELECT wj_attendance2016.ShopID
FROM wj_attendance2016
WHERE (wj_attendance2016.EmployeeID=3372) AND (wj_attendance2016.SerialDate Between 20160101 And 20191016)

Same error message.
 

Buxtona

Registered User.
Local time
Today, 13:24
Joined
Jun 20, 2019
Messages
17
and silly thing is:

SELECT wj_attendance.ShopID
FROM wj_attendance
WHERE (wj_attendance.EmployeeID=3372) AND (wj_attendance.SerialDate Between 20160101 And 20191016)
UNION
SELECT wj_attendance2017.ShopiD
FROM wj_attendance2017
WHERE (wj_attendance2017.EmployeeID=3372) AND (wj_attendance2017.SerialDate Between 20160101 And 20191016)

If i only combine 2 tables it works
 

Minty

AWF VIP
Local time
Today, 13:24
Joined
Jul 26, 2013
Messages
10,367
Simple debug experiment; cut and paste the individual selects into fresh queries to make sure they work?
 

isladogs

MVP / VIP
Local time
Today, 13:24
Joined
Jan 14, 2017
Messages
18,207
Are there any results for the 2016 table using the WHERE filter if its run on its own?

What happens if you do this in 2 stages?
1. Create qryUnion with no filters
2. Create another query filtering qryUnion

Also, as possibly implied in post #1 table is the plan to combine all 3 tables into one?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:24
Joined
May 7, 2009
Messages
19,227
if it works on 2, check the last table.
does it have the fields specified.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:24
Joined
Sep 21, 2011
Messages
14,217
I'm confused now as your initial error message was on the 2017 file.?

and silly thing is:

SELECT wj_attendance.ShopID
FROM wj_attendance
WHERE (wj_attendance.EmployeeID=3372) AND (wj_attendance.SerialDate Between 20160101 And 20191016)
UNION
SELECT wj_attendance2017.ShopiD
FROM wj_attendance2017
WHERE (wj_attendance2017.EmployeeID=3372) AND (wj_attendance2017.SerialDate Between 20160101 And 20191016)

If i only combine 2 tables it works
 

Buxtona

Registered User.
Local time
Today, 13:24
Joined
Jun 20, 2019
Messages
17
Are there any results for the 2016 table using the WHERE filter if its run on its own? yes a years worth of data as expected

What happens if you do this in 2 stages?
1. Create qryUnion with no filters - same error message
2. Create another query filtering qryUnion

Also, as possibly implied in post #1 table is the plan to combine all 3 tables into one?
yes i want to join all three tables to get results from all 3 years
 

Users who are viewing this thread

Top Bottom