关于规则中列顺序,前后必须一致。否则会出现如下情况:
use test;
select cust_name ,cust_email,cust_contact from customers where cust_state in (‘IL’,’IN’,’MI’) union all
select cust_name,cust_contact,cust_email from customers where cust_name = ‘Fun4All’
返回结果为:
cust_name | cust_email | cust_contact |
---|---|---|
Village Toys | sales@villagetoys.com | John Smith |
Fun4All | jjones@fun4all.com | Jim Jones |
The Toy Store | Kim Howard | |
Fun4All | Jim Jones | jjones@fun4all.com |
Fun4All | Denise L. Stephens | dstephens@fun4all.com |
列的顺序一致,才会返回正确结果
use test;
select cust_name ,cust_email,cust_contact from customers where cust_state in (‘IL’,’IN’,’MI’) union all
select cust_name,cust_email,cust_contact from customers where cust_name = ‘Fun4All’
返回结果:
cust_name | cust_email | cust_contact |
---|---|---|
Village Toys | sales@villagetoys.com | John Smith |
Fun4All | jjones@fun4all.com | Jim Jones |
The Toy Store | Kim Howard | |
Fun4All | jjones@fun4all.com | Jim Jones |
Fun4All | dstephens@fun4all.com | Denise L. Stephens |