0
我有2個表用戶和訂單,我要得到用戶和他的訂單數Mysql的模擬FULL OUTER JOIN
SELECT `users`.*, `orders`.*,count(*) FROM `users` LEFT JOIN orders ON
`users`.`id` = `orders`.`user_id`
UNION SELECT `users`.*, `orders`.*,count(*) FROM users
RIGHT JOIN orders ON `users`.`id` = `orders`.`user_id`
此查詢選擇用戶並有秩序用戶的順序數,但是不選擇用戶誰不有訂單。
我想獲得
user orders
John 5
Thomas 0
Mike 8
我能得到什麼
user orders
John 5
Mike 8
如何獲得用戶也誰沒有訂單怎麼辦?
如果你只想'用戶'和'訂單'列爲什麼要做一個'SELECT *'? –
@Declan_K好,但它不是我想的問題 – Wizard