项目场景:
1.将多张无关联关系表的查询结果发到同一张表中显示
2.添加一个新字段,只用在查询,不会对数据库影响
解决方案:
1.0
获取的结果会在一张新的表中显示
使用前提是每个查询语句的字段数量,类型一致
select name,age,num,date from table1
where name is not null
union all
select name,age,num,date from table2
union all
select string,int,int,date from table3
也可以用在关联查询的SQL中,最后可以进行order排序和limit分页
select name,age,num,date from table1
left join data1 on data_ID=data.ID
union all
select name,age,num,date from table2
left join data2 on data_ID=data.ID
union all
select string,int,int,date from table3
order by age
limit 10
2.0
注意:查询时生成的字段不可以用作where条件,查询完后生成的字段
select '类型' as type ,* from table
select 值 as 字段名 from table