P
Phil
Imagine a fairly basic select query. It joins 7 tables together. One
of those tables has two identical fields, say primary_licensor and
secondary_licensor.
This query joins one of these tables to primary_licensor, and results in
4 records. I call this primary_licensor_query.
I change this query just by changing that join from primary_licensor to
secondary_licensor, which results in zero records found. I call this
secondary_licensor_query.
I cut and paste the SQL for each of these two queries into a third
query, seperated by the word "union". I call this all_licensor_query.
This SHOULD result in a query that returns 4 records + 0 records for a
total of 4 records.
It returns two records. WTF?
I will post it, but it has a couple of ugly iff statements. Note that I
can delete the word "union" and everything after it, and it returns 4
records. Please help.
Phil
SELECT invoice_h.invoice_date, invoice_h.status, licensor.labels,
item_types.name, territory.name, IIf(territory!name="Foreign_1" Or
territory!name="Foreign_2" Or territory!name="Foreign_3","YES","NO") AS
[Foreign], invoice_d!ship_qty*invoice_d!price AS Ext_price,
invoice_d.ship_qty, invoice_d.item_id, item.old_sku
FROM territory INNER JOIN (customer INNER JOIN (((item_types INNER JOIN
(licensor INNER JOIN item ON licensor.licensor_id =
item.pri_licensor_id) ON item_types.type_id = item.item_type) INNER JOIN
invoice_d ON item.item_id = invoice_d.item_id) INNER JOIN invoice_h ON
invoice_d.invoice_id = invoice_h.invoice_id) ON customer.customer_id =
invoice_h.customer_id) ON territory.territory_id = customer.territory_id
WHERE (((invoice_h.invoice_date)=#5/2/2006#) AND ((invoice_h.status)=8
Or (invoice_h.status)=9) AND ((licensor.labels) Like "Eric*") AND
((item.old_sku)="4494060"))
union
SELECT invoice_h.invoice_date, invoice_h.status, licensor.labels,
item_types.name, territory.name, IIf(territory!name="Foreign_1" Or
territory!name="Foreign_2" Or territory!name="Foreign_3","YES","NO") AS
[Foreign], invoice_d!ship_qty*invoice_d!price AS Ext_price,
invoice_d.ship_qty, invoice_d.item_id, item.old_sku
FROM licensor INNER JOIN (territory INNER JOIN (customer INNER JOIN
(((item_types INNER JOIN item ON item_types.type_id = item.item_type)
INNER JOIN invoice_d ON item.item_id = invoice_d.item_id) INNER JOIN
invoice_h ON invoice_d.invoice_id = invoice_h.invoice_id) ON
customer.customer_id = invoice_h.customer_id) ON territory.territory_id
= customer.territory_id) ON licensor.licensor_id = item.sec_licensor_id
WHERE (((invoice_h.invoice_date)=#5/2/2006#) AND ((invoice_h.status)=8
Or (invoice_h.status)=9) AND ((licensor.labels) Like "eric*") AND
((item.old_sku)="4494060"));
of those tables has two identical fields, say primary_licensor and
secondary_licensor.
This query joins one of these tables to primary_licensor, and results in
4 records. I call this primary_licensor_query.
I change this query just by changing that join from primary_licensor to
secondary_licensor, which results in zero records found. I call this
secondary_licensor_query.
I cut and paste the SQL for each of these two queries into a third
query, seperated by the word "union". I call this all_licensor_query.
This SHOULD result in a query that returns 4 records + 0 records for a
total of 4 records.
It returns two records. WTF?
I will post it, but it has a couple of ugly iff statements. Note that I
can delete the word "union" and everything after it, and it returns 4
records. Please help.
Phil
SELECT invoice_h.invoice_date, invoice_h.status, licensor.labels,
item_types.name, territory.name, IIf(territory!name="Foreign_1" Or
territory!name="Foreign_2" Or territory!name="Foreign_3","YES","NO") AS
[Foreign], invoice_d!ship_qty*invoice_d!price AS Ext_price,
invoice_d.ship_qty, invoice_d.item_id, item.old_sku
FROM territory INNER JOIN (customer INNER JOIN (((item_types INNER JOIN
(licensor INNER JOIN item ON licensor.licensor_id =
item.pri_licensor_id) ON item_types.type_id = item.item_type) INNER JOIN
invoice_d ON item.item_id = invoice_d.item_id) INNER JOIN invoice_h ON
invoice_d.invoice_id = invoice_h.invoice_id) ON customer.customer_id =
invoice_h.customer_id) ON territory.territory_id = customer.territory_id
WHERE (((invoice_h.invoice_date)=#5/2/2006#) AND ((invoice_h.status)=8
Or (invoice_h.status)=9) AND ((licensor.labels) Like "Eric*") AND
((item.old_sku)="4494060"))
union
SELECT invoice_h.invoice_date, invoice_h.status, licensor.labels,
item_types.name, territory.name, IIf(territory!name="Foreign_1" Or
territory!name="Foreign_2" Or territory!name="Foreign_3","YES","NO") AS
[Foreign], invoice_d!ship_qty*invoice_d!price AS Ext_price,
invoice_d.ship_qty, invoice_d.item_id, item.old_sku
FROM licensor INNER JOIN (territory INNER JOIN (customer INNER JOIN
(((item_types INNER JOIN item ON item_types.type_id = item.item_type)
INNER JOIN invoice_d ON item.item_id = invoice_d.item_id) INNER JOIN
invoice_h ON invoice_d.invoice_id = invoice_h.invoice_id) ON
customer.customer_id = invoice_h.customer_id) ON territory.territory_id
= customer.territory_id) ON licensor.licensor_id = item.sec_licensor_id
WHERE (((invoice_h.invoice_date)=#5/2/2006#) AND ((invoice_h.status)=8
Or (invoice_h.status)=9) AND ((licensor.labels) Like "eric*") AND
((item.old_sku)="4494060"));