欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

联合查询-mysql 结构不同多表查询,请教语句

程序员文章站 2022-04-21 09:37:51
...
联合查询mysql多表查询

我原来有几个结构相同的3个表 tab1、tab2、tab3

这3个表都有字段

col1、col2、col3

原来使用语句

(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";

查询的

现在新加了个表 tab4 字段多了个col4

即:col1、col2、col3、col4

再用上面的语句 多加个个
(select * from tab4 where col1='$wd' or col2 LIKE '$wd%')
union all
后 查询提示

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

请问有什么语句可以带新加的tab4正常查询吗?