首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

[Teach Youself SQL in 十 Minutes] combining queries

2012-07-25 
[Teach Youself SQL in 10 Minutes] combining queriesSELECT cust_name, cust_contact, cust_emailFROM C

[Teach Youself SQL in 10 Minutes] combining queries

SELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_state IN ('IL','IN','MI')UNIONSELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_name = 'Fun4All'ORDER BY cust_name, cust_contact;

SELECT statements used. You'll notice that when executed individually, the first SELECT statement returns three rows, and the second SELECT statement returns two rows. However, when the two SELECT statements are combined with a UNION, only four rows are returned, not five.

SELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_state IN ('IL','IN','MI')UNION ALLSELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_name = 'Fun4All';

SELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_state IN ('IL','IN','MI')UNIONSELECT cust_name, cust_contact, cust_emailFROM CustomersWHERE cust_name = 'Fun4All'ORDER BY cust_name, cust_contact;

?

热点排行