public function getUserList() {
$sql = "SELECT users.id, users.name, about.profile_img, user_game_info.at_game, SUM(user_img.likes) AS likes FROM users
JOIN about ON users.id = about.uid
JOIN user_game_info ON about.uid = user_game_info.uid
INNER JOIN user_img ON user_game_info.uid = user_img.uid";
$query = $this->db->query($sql, PDO::FETCH_ASSOC);
if ($query->rowCount()) {
$userList = $query->fetchAll();
return $userList;
}
return false;
}
它的工作原理,但如果我的user_img沒有UID,我想告訴喜歡數0 該查詢返回只有img_user有UID,如果沒有它沒沒有任何回報。MySQL的加入任何回報,如果沒有數據
這僅適用於user_img。例如,查詢必須爲UID 3.返回0,因爲user_img沒有UID = 3,但它不返回任何數據UID 3.
使用'outer join'而不是... – sgeddes