SQL左连接数组的部分是空的

时间:2013-03-08 20:58:56

标签: php mysql sql arrays left-join

我的问题是以下代码,数组的注释和评级区域应该在其中有一个注释,因为数据库历史表... ...

 SELECT users.uid, users.username, history.user_id, history.comment, history.rating
 FROM history
 LEFT JOIN users
 ON users.uid=history.user_id
 WHERE history.book_id="$bid"

它返回:

 Array ( [uid] => 3 [username] => Reign [user_id] => 3 [comment] => [rating] => )

1 个答案:

答案 0 :(得分:4)

然后你想使用INNER JOINLEFT JOIN将返回NULL个值。

SELECT users.uid, users.username, history.user_id, history.comment, history.rating
FROM history
INNER JOIN users
ON users.uid=history.user_id
WHERE history.book_id="$bid"