当前位置:Gxlcms > PHP教程 > mysql三表join联查

mysql三表join联查

时间:2021-07-01 10:21:17 帮助过:6人阅读

话说:comments表 , 其中message_user_id为where条件
其中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

人气教程排行