在公司的系統上開發時,我遇到了一個兩難的問題,而且項目管理不是關於!無法聯合選擇並加入聯盟
SELECT clients_owner.Name, clients_owner.`number`, clients_shops.Shopname, clients_shops.PostCode, clients_shops.Location
FROM clients_shops inner join clients_owner ON
clients_owner.ShopID = clients_shops.ShopID
UNION
SELECT clients_fans.Fan
FROM clients_shops inner join clients_fans ON
clients_shops.ShopID = clients_fans.ShopID
下面的查詢返回以下錯誤:
1222 - The used SELECT statements have a different number of columns
但是使用這個作爲一個例子:Mysql JOIN (multiple) tables被標記爲答案,這樣的查詢是明顯有效。我哪裏錯了?
而下面的加入合併兩個表:
SELECT
clients_owner.Name, clients_owner.Number, clients_shops.Shopname, clients_shops.PostCode,
clients_shops.Location FROM clients_shops INNER JOIN clients_owner on
clients_owner.ShopID = clients_shops.ShopID
工程順利
'UNION'合併行,所以他們必須要對兩個查詢相同。看起來你正試圖向現有記錄添加另一列。這應該使用'JOIN'完成。 – MarcinJuraszek