我正在尝试进行简单的 mysql 选择查询,我有 3 个表
post: post_id...
tags: tag_id, tag_name
post_tag: id_post, id_tag
我写了这个查询:
$sql=mysql_query("select * from post
LEFT JOIN post_tag
ON post_tag.id_post = post.post_id
LEFT JOIN tags
ON post_tag.id_tag = tags.tag_id
GROUP BY post_id
ORDER BY post_id
DESC LIMIT 5");
但是即使有更多具有相同post_id的标签,每个帖子我也只能获得一个标签?
while($row=mysql_fetch_array($sql))
{
$post_id =$row['post_id '];
$tag_name=$row['tag_name'];
echo $post_id $tag_name;
}