42.笔记 MySQL学习——ALL ANY和SOME子查询

来源:互联网 发布:苹果cydiapp助手源码 编辑:程序博客网 时间:2024/06/05 20:13

42.笔记 MySQL学习——ALL ANY和SOME子查询

运算符ALL和ANY常与某个关系比较运算符结合在一起使用。

会测试比较值与子查询返回的全部或部分值是否匹配。

例如:

mysql> select last_name,first_name,birth frompresident where birth <= all (select birth from president);

+------------+------------+------------+

| last_name | first_name | birth      |

+------------+------------+------------+

| Washington | George     | 1732-02-22 |

+------------+------------+------------+

1 row in set (0.00 sec)

 

mysql> select last_name,first_name,birth frompresident where birth <= any (select birth from president);

+------------+-------------+------------+

| last_name | first_name  | birth      |

+------------+-------------+------------+

| Washington | George      | 1732-02-22 |

| Adams     | John        | 1735-10-30 |

| Jefferson | Thomas      | 1743-04-13 |

| Madison   | James       | 1751-03-16 |

| Monroe    | James       | 1758-04-28 |

| Adams     | John Quincy | 1767-07-11 |

| Jackson   | Andrew      | 1767-03-15 |

| Van Buren | Martin      | 1782-12-05 |

| Harrison  | William H.  | 1773-02-09 |

| Tyler     | John        | 1790-03-29 |

| Polk      | James K.    | 1795-11-02 |

| Taylor    | Zachary     | 1784-11-24 |

| Fillmore  | Millard     | 1800-01-07 |

| Pierce    | Franklin    | 1804-11-23 |

| Buchanan  | James       | 1791-04-23 |

| Lincoln   | Abraham     | 1809-02-12 |

| Johnson   | Andrew      | 1808-12-29 |

| Arthur    | Chester A.  | 1829-10-05 |

| Cleveland | Grover      | 1837-03-18 |

| Roosevelt | Theodore    | 1858-10-27 |

| Wilson    | Woodrow     | 1856-12-19 |

| Coolidge  | Calvin      | 1872-07-04 |

| Hoover    | Herbert C.  | 1874-08-10 |

| Roosevelt | Franklin D. | 1882-01-30 |

| Truman    | Harry S     | 1884-05-08 |

| Eisenhower | Dwight D.   | 1890-10-14 |

| Kennedy   | John F.     | 1917-05-29 |

| Johnson   | Lyndon B.   | 1908-08-27 |

| Nixon     | Richard M.  | 1913-01-09 |

| Ford      | Gerald R.   | 1913-07-14 |

| Carter    | James E.    | 1924-10-01 |

| Reagan    | Ronald W.   | 1911-02-06 |

| Bush      | George H.W. | 1924-06-12 |

| Clinton   | William J.  | 1946-08-19 |

| Bush      | George W.   | 1946-07-06 |

| Obama     | Barack H.   | 1961-08-04 |

+------------+-------------+------------+

36 rows in set (0.00 sec)

 

IN 和 NOT IN是 = ANY 和<> ALL的简写。

IN的含义是等于子查询返回的某个行。

NOT IN的含义是 不等于子查询所返回的任何行。

 

 

 

阅读全文
0 0
原创粉丝点击