例如 一个表
CREATE TABLE `chezhu1_temp` (
`phoneNo` varchar(30) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`sex` int(11) DEFAULT NULL,
`hasCar` char(1) DEFAULT '1',
`CityID` char(4) DEFAULT NULL,
`Region` char(5) DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL,
PRIMARY KEY (`phoneNo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8其他的表是跟其差不多 大概有400-500个表 怎么能够放到一个表中 利于搜索呢
CREATE TABLE `chezhu1_temp` (
`phoneNo` varchar(30) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`sex` int(11) DEFAULT NULL,
`hasCar` char(1) DEFAULT '1',
`CityID` char(4) DEFAULT NULL,
`Region` char(5) DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL,
PRIMARY KEY (`phoneNo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8其他的表是跟其差不多 大概有400-500个表 怎么能够放到一个表中 利于搜索呢
完全一样:
select * from (
select * from b1
union all
select * from b1
union all
...
select * from bn) a where phoneNo='11231'
select * from tab1
union all
select * from tab2
union all
.........
as
select 字段列表 from tab1
union all
select 字段列表 from tab2
union all
.........
那就只能把字段一个一个列出来了。
select col1, co2 ,... from table1
union all
select col1, co2 ,... from table2
..
表有些太多了,你的SQL会很长。
一般是建议把这些相同的数据放到同一张表中去,这样速度,效率会比较好。
insert intoinsert into chezhu1_temp(id,name)
select uid,ss from tab1
union all
select userid,user from tab2
............