SQL组合查询

组合查询:

利用UNION,将多条SELECT语句的结果合并成一个一个结果集。

比如:

输入:

要找到以下符合以下两个条件之一的顾客信息如cust_name,cust_contact,cust_email

一:cust_state是‘IL’,‘IN’,‘MI’的。

二:cust_name是‘Fun4all’的。 

第一种解决方案   两个查询中加个UNION:

SELECT cust_name,cust_contact,cust_email
FROM Customers
WHERE cust_state IN ('IL','IN','MI')
UNION
SELECT cust_name,cust_contact,cust_email
FROM  Customers
WHERE cust_name='Fun4ALL'

第二种解决方案 使用WHERE:

SELECT cust_name,cust_contact,cust_email
FROM Customers
WHERE cust_state IN ('IL','IN','MI')
OR  cust_name='Fun4ALL'
原文地址:https://www.cnblogs.com/liuguangshou123/p/13944015.html