Hey guys so my query isn’t returning my union results when I specify my main selects column names, aka
SELECT inspection_number, region, report_date,
inspection_type AS type, customer, customer_number, shipper, po
FROM reports
JOIN (
(
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `berries`
)
UNION (
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `melons`
)
UNION (
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `citrus`
)
UNION (
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `table_grapes`
)
UNION (
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `tree_fruit`
)
UNION (
SELECT `key`, `report_key`, `shipper`, `po`, `commodity`, `label`, `status`
FROM `lot`
)
) fruits ON inspection_number = fruits.report_key
WHERE fruits.status = '0' OR fruits.status = '1'
ORDER BY report_date DESC
Does not return key, report_key, shipper, po, commodity, label, or status
Strangely running
SELECT *
inspection_type AS type, customer, customer_number, shipper, po
FROM reports
JOIN ( -- etc.....
Will? How can I fix this?
The fruits derived table does have the columns mentioned but in your main select you don’t mention any of them; you only mention the columns inspection_number, region, report_date, inspection_type from reports – therefore it only shows them.
If you want to include the fruits columns, you need to specify them in your main select statement
i.e. something like: