联合选择不显示联合结果
大家好,当我指定主选择列名称时,我的查询不会返回联合结果,即
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
不返回 key
、report_key
、shipper
、po
、commodity
、label
或 status
运行异常
SELECT *
inspection_type AS type, customer, customer_number, shipper, po
FROM reports
JOIN ( -- etc.....
会吗?我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fruits 派生表确实包含提到的列,但在您的主要选择中您没有提及任何列;您只提到报告中的列 Inspection_number、region、report_date、inspection_type - 因此它只显示它们。
如果您想包含水果列,您需要在主选择语句中指定它们,
例如:
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: