联合选择不显示联合结果

发布于 2025-01-08 09:03:06 字数 1393 浏览 0 评论 0原文

大家好,当我指定主选择列名称时,我的查询不会返回联合结果,即

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

不返回 keyreport_keyshipperpocommoditylabelstatus

运行异常

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风不识月 2025-01-15 09:03:06

fruits 派生表确实包含提到的列,但在您的主要选择中您没有提及任何列;您只提到报告中的列 Inspection_number、region、report_date、inspection_type - 因此它只显示它们。

如果您想包含水果列,您需要在主选择语句中指定它们,

例如:

SELECT inspection_number, region, report_date, 
inspection_type, key, report_key, shipper, po, commodity, label, status AS type, customer, customer_number, shipper, po, key, report_key, shipper, po, commodity, label, status
FROM reports
JOIN (

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:

SELECT inspection_number, region, report_date, 
inspection_type, key, report_key, shipper, po, commodity, label, status AS type, customer, customer_number, shipper, po, key, report_key, shipper, po, commodity, label, status
FROM reports
JOIN (
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文