Mysql three-table join joint query

Source: Internet
Author: User
Mysql three-table join statement: comments table, where message_user_id is the where condition
Here, message_id needs to obtain the title of the corresponding id in the messages table
User_id must obtain the name in the users table.

SQL statement


Reply to discussion (solution)

Select *, (select title from messages where id =. message_id) as message_title, (select name from users where user_id =. message_user_id) as user_name from comments as a where. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.