图像表
+----------+---------------+---------------+--------------+
| image_id | image_user_id | profile_image | image_status |
+----------+---------------+---------------+--------------+
| 1 | 1 | 834098.png | live |
| 2 | 2 | 347903.jpg | pending |
| 3 | 3 | 447903.jpg | pending |
+----------+---------------+---------------+--------------+
评论表
+------------+-----------------+---------------+
| comment_id | comment_user_id | text |
+------------+---------------------------------+
| 1 | 1 | great article |
| 2 | 2 | not bad |
| 3 | 3 | lorem |
+------------+-----------------+---------------+
SQL 查询
SELECT
profile_image,
comment_id
FROM comment
LEFT JOIN image ON image_user_id = comment_user_id
WHERE image_status = 'live'
LIMIT 7
上述代码仅在相关image_pending
字段设置为时读取注释live
。我如何更改代码以使其profile_image
在image_status
is时读取live
?
上面的代码将输出:
array( 'profile_image' => '834098.png', 'comment_id' => 1 )
它应该输出:
array(
array( 'profile_image' => '834098.png', 'comment_id' => 1 )
array( 'comment_id' => 2 )
array( 'comment_id' => 3 )
)