我有一個4表,其中我需要從db中獲取用戶信息,州名稱,分支名稱和孩子總數。Mysql查詢獲取全部孩子?
我用下面的SQL
SELECT `user_id` , `user_name` , state_name, branch_name
FROM `user`
LEFT JOIN state ON state_id = user_state_id
LEFT JOIN branch ON branch_id = user_branch_id
,但我也需要得到孩子的計數爲每個用戶,所以我用下面的查詢
SELECT `user_id` , `user_name` , state_name, branch_name, count(child_id)
FROM `user`
LEFT JOIN state ON state_id = user_state_id
LEFT JOIN branch ON branch_id = user_branch_id
LEFT JOIN child on parent_id = user_id group by user_id
我要問一個問題,它是確定使用在整個查詢中計數組是由這個影響來自此查詢連接的數據