2012-02-23 168 views
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_keyshipperpocommoditylabel,或status

奇怪運行

SELECT * 
inspection_type AS type, customer, customer_number, shipper, po 
FROM reports 
JOIN (-- etc..... 

Will?我怎樣才能解決這個問題?

回答

1

水果派生表確實有提到的列,但在你的主要選擇你沒有提到他們中的任何一個;您只能從報告中提及列檢查編號,區域,report_date,inspection_type - 因此它只顯示它們。

如果要包括水果列,您需要在主SELECT語句中指定它們

即是這樣的:

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 (
+0

只是想通了這一點太;) – ehime 2012-02-23 21:06:11