Home >Backend Development >PHP Tutorial >mysql三表join联查

mysql三表join联查

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:28:042118browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn