mysql三表join联查
程序员文章站
2022-06-04 17:22:14
...
话说:comments表 , 其中message_user_id为where条件
其中message_id需要获取messages表中对应id的title
其中user_id需要获取users表中的name
求sql语句
其中message_id需要获取messages表中对应id的title
其中user_id需要获取users表中的name
求sql语句
回复讨论(解决方案)
select *,(select title from messages where id=a.message_id) as message_title,(select name from users where user_id=a.message_user_id) as user_name from comments as a where a.message_user_id = xxx;
select message_user_id, messages.title, users.name from comments, messages, users while message_id = messages.id and user_id = users.id and message_user_id = $id