zoukankan      html  css  js  c++  java
  • sql 基础--mysql 5 (8)

    15.组合查询 union

    mysql> select uid,first_name,price from pw_price where uid >2 union select uid,first_name,price from
     pw_price where price>=1000;
    +-----+------------+-------+
    | uid | first_name | price |
    +-----+------------+-------+
    |   3 | li         |  2000 |
    |   2 | zhang      |  1000 |
    +-----+------------+-------+
    2 rows in set (0.00 sec)
    
    mysql> select uid,first_name,price from pw_price where uid >2 or price>=1000;
    +-----+------------+-------+
    | uid | first_name | price |
    +-----+------------+-------+
    |   2 | zhang      |  1000 |
    |   3 | li         |  2000 |
    +-----+------------+-------+
    2 rows in set (0.00 sec)

    不去重显示所有结果

    mysql> select uid,first_name,price from pw_price where uid >2 union all select uid,first_name,pri
    from pw_price where price>=1000;
    +-----+------------+-------+
    | uid | first_name | price |
    +-----+------------+-------+
    |   3 | li         |  2000 |
    |   2 | zhang      |  1000 |
    |   3 | li         |  2000 |
    +-----+------------+-------+
    3 rows in set (0.00 sec)

    组合结果排序 放在最后的select语句中

    mysql> select uid,first_name,price from pw_price where uid >2 union select uid,first_name,price from
     pw_price where price>=1000 order by uid desc;
    +-----+------------+-------+
    | uid | first_name | price |
    +-----+------------+-------+
    |   3 | li         |  2000 |
    |   2 | zhang      |  1000 |
    +-----+------------+-------+
    2 rows in set (0.00 sec)
  • 相关阅读:
    chkconfig命令
    Office 2010 与搜狗输入法兼容问题
    【转】WAS入门简介
    UTF8GB2312GBK
    System.getProperty
    Hibernate 事务方法保存clob类型数据
    Eclipse 或者 Myeclipse 提示选择工作空间设置
    request
    那些操蛋的人生
    Java新手入门很重要的几个基本概念
  • 原文地址:https://www.cnblogs.com/wjw334/p/4304984.html
Copyright © 2011-2022 走看看