首頁 >後端開發 >php教程 >mysql三表join联查

mysql三表join联查

WBOY
WBOY原創
2016-06-23 13:28:042110瀏覽

话说: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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn