How does MySQL implement multiple tables or queries?

Source: Internet
Author: User
I want to query username in two tables like that. If one table has this data, true is returned, but MySQL returns true only if both tables have this data. Is there any way to implement such a query? (If either of the two tables has data, true is returned)


I want to query username in two tables like that. If one table has this data, true is returned, but MySQL returns true only if both tables have this data.

Is there any way to implement such a query? (If either of the two tables has data, true is returned)

Reply content:


I want to query username in two tables like that. If one table has this data, true is returned, but MySQL returns true only if both tables have this data.

Is there any way to implement such a query? (If either of the two tables has data, true is returned)

select * from user_agent, user_cleck where user_agent.username = 'huibao' or user_clerk.username = 'huibao'Can this happen?

select * from table1, table2Multi-table joint query. The subject only obtains a collection of the results of two single-table queries.UNION.

1. Result collection

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

2. Retrieve the collection of results and remove repeated items.

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

The subject can be either of them.

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.