How does MySQL implement multiple tables or queries?

Source: Internet
Author: User
Keywords Php mysql


I want to query username like that in two tables, only one of the tables has this data to return true, but the MySQL judge must have two tables to return true.

Is there any way to implement such a query? (Returns True if there is data in any of the two tables)

Reply content:


I want to query username like that in two tables, only one of the tables has this data to return true, but the MySQL judge must have two tables to return true.

Is there any way to implement such a query? (Returns True if there is data in any of the two tables)

select * from user_agent, user_cleck where user_agent.username = 'huibao' or user_clerk.username = 'huibao'Is that OK?

select * from table1, table2is a multi-table joint query, the case of the main problem is only two single-table query results collection, should be used in union.

1. Result Collection

select * from user_agent where username='{$username}' union all select * from user_clerk where username='{$username}';

2, result collection, and remove duplicates

select * from user_agent where username='{$username}' union select * from user_clerk where username='{$username}';

The situation of the main problem, both kinds of can.

  • 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.