博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql union 组合查询
阅读量:4962 次
发布时间:2019-06-12

本文共 2117 字,大约阅读时间需要 7 分钟。

 

mysql> select * from test    -> ;+----+------------+-------+-----------+| id | name       | score | subject   |+----+------------+-------+-----------+|  1 | xiaoming   |    89 | shuxue    ||  2 | xiaohong   |    89 | shuxue    ||  3 | xiaohong   |    80 | english   ||  4 | xiaohong   |    80 | physics   ||  5 | xiaohong   |    80 | astronaut ||  6 | xiaoming   |    80 | physics   ||  7 | xiaoming   |    80 | astronaut ||  8 | xiaoming   |    80 | english   ||  9 | xiaobai    |    80 | astronaut || 10 | 1.2xiaobai |    80 | english   || 11 | 2.2xiaobai |    80 | physics   || 12 | 3xiaobai   |    80 | shuxue    || 13 | 123xiaohei |    80 | astronaut || 14 | xiaohei    |    80 | shuxue    || 15 | xiaohei    |    80 | physics   || 16 | .12xiaohei |    80 | english   |+----+------------+-------+-----------+16 rows in set (0.00 sec)mysql> select * from user;+------+----------+-----------+| id   | name     | address   |+------+----------+-----------+|    1 | xiaoming | beijing   ||    2 | xiaobai  | shandong  ||    3 | xiaohong | suzhou    ||    4 | xiaohei  | changchun |+------+----------+-----------+4 rows in set (0.00 sec)mysql> select id,name from user where name="xiaohong" union select id,name from test where name="xiaoming";+------+----------+| id   | name     |+------+----------+|    3 | xiaohong ||    1 | xiaoming ||    6 | xiaoming ||    7 | xiaoming ||    8 | xiaoming |+------+----------+5 rows in set (0.00 sec)mysql> select id,name from user where name="xiaohong" union all select id,name from test where name="xiaoming";+------+----------+| id   | name     |+------+----------+|    3 | xiaohong ||    1 | xiaoming ||    6 | xiaoming ||    7 | xiaoming ||    8 | xiaoming |+------+----------+5 rows in set (0.00 sec)mysql> select id,name from user where name="xiaohong" union all select id,name from test where name="xiaoming" order by id;+------+----------+| id   | name     |+------+----------+|    1 | xiaoming ||    3 | xiaohong ||    6 | xiaoming ||    7 | xiaoming ||    8 | xiaoming |+------+----------+5 rows in set (0.00 sec)

 

 

 

 

转载于:https://www.cnblogs.com/sea-stream/p/11312829.html

你可能感兴趣的文章
注册页实现激活邮箱验证(asp.net c#) 详细实现
查看>>
打造完美的IE网页木马
查看>>
CF1109A Sasha and a Bit of Relax
查看>>
【Foreign】登山 [DP][数学]
查看>>
【codeforces】【比赛题解】#948 CF Round #470 (Div.2)
查看>>
关于实现线程死锁的一个例子
查看>>
FMDB保存数据小数
查看>>
JAVA中抽象类的一些总结
查看>>
分页, 解析器, 渲染器
查看>>
fedora输入法
查看>>
关于数组去重的几种方法-------javascript描述
查看>>
Vue.js系列之三模板语法
查看>>
hihoCoder #1238 Total Highway Distance
查看>>
JAVA基础(7)-数组的排序
查看>>
JFinal使用笔记1-部署demo项目到本地tomcat
查看>>
php 有时候难以输出显示的信息可以用ob缓冲区来做
查看>>
挖地雷
查看>>
luogu P2617 Dynamic Rankings(主席树)
查看>>
MongoDB 安装与配置
查看>>
Linux 常用命令
查看>>