Combined query-mysql multi-table query with different structures.

Source: Internet
Author: User
I have three tables with the same structure, tab1, tab2, and tab3, which all have the fields col1, col2, and col3. The original use statement (select * fromtab1wherecol1 & #39; $ wd & #39; orcol2LIKE & #39; $ wd % & #39;) unionall (select * fromtab1wherecol1 & #39; $ wd & #39; orcol2LIKE & #39; $ wd % & #39;) unionall (select * fromtab1w joint query mysql multi-table query

I originally had several tab1, tab2, and tab3 tables with the same structure.

All three tables have fields.

Col1, col2, col3

Original statement

(Select * from tab1 where col1 = '$ wd' or col2 LIKE '$ wd % ')
Union all
(Select * from tab1 where col1 = '$ wd' or col2 LIKE '$ wd % ')
Union all
(Select * from tab1 where col1 = '$ wd' or col2 LIKE '$ wd %') LIMIT 0, 20 ";

Queried

Now we have added a table with tab4 fields and col4 fields.

Namely: col1, col2, col3, col4

Use the preceding statement to add more
(Select * from tab4 where col1 = '$ wd' or col2 LIKE '$ wd % ')
Union all
After query prompt

Invalid query: The used SELECT statements have a different number of columns

Is there any statement that can be properly queried with the newly added tab4?

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.