当前位置: 首页 > wzjs >正文

需要建设网站的网站建设流程行情

需要建设网站的,网站建设流程行情,王烨桦,何如做外贸网站推网欢迎拜访:雾里看山-CSDN博客 本篇主题:【MySQL】表的内联和外联 发布时间:2025.2.24 隶属专栏:MySQL 目录 内连接语法案例 外连接左外连接语法案例 右外连接语法案例 练习运用左外连接运用右外连接 表的连接分为内连和外连 内连接…

欢迎拜访:雾里看山-CSDN博客
本篇主题:【MySQL】表的内联和外联
发布时间:2025.2.24
隶属专栏:MySQL

在这里插入图片描述

目录

  • 内连接
    • 语法
    • 案例
  • 外连接
    • 左外连接
      • 语法
      • 案例
    • 右外连接
      • 语法
      • 案例
    • 练习
      • 运用左外连接
      • 运用右外连接

表的连接分为内连和外连

内连接

内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我们前面文章的查询都是内连接,也是在开发过程中使用的最多的连接查询。

语法

select 字段 from1 inner join2 on 连接条件 and 其他条件;

案例

  1. 显示SMITH的名字和部门名称

用之前的方法

mysql> select ename, dname from emp, dept where emp.deptno=dept.deptno and ename='SMITH';
+-------+----------+
| ename | dname    |
+-------+----------+
| SMITH | RESEARCH |
+-------+----------+
1 row in set (0.00 sec)

用标准内连接

mysql> select ename, dname from emp inner join dept on emp.deptno=dept.deptno and ename='SMITH';
+-------+----------+
| ename | dname    |
+-------+----------+
| SMITH | RESEARCH |
+-------+----------+
1 row in set (0.00 sec)

两种方式混合使用,更好的区分笛卡尔积和筛选条件

mysql> select ename, dname from emp inner join dept on emp.deptno=dept.deptno where ename='SMITH';
+-------+----------+
| ename | dname    |
+-------+----------+
| SMITH | RESEARCH |
+-------+----------+
1 row in set (0.00 sec)

外连接

外连接分为左外连接和右外连接

左外连接

如果联合查询,左侧的表完全显示我们就说是左外连接。

语法

select 字段名 from 表名1 left join 表名2 on 连接条件

案例

前期准备:

mysql> create table stu (id int, name varchar(30));-- 学生表
Query OK, 0 rows affected (0.03 sec)mysql> desc stu;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)mysql> insert into stu values(1,'jack'),(2,'tom'),(3,'kity'),(4,'nono');
Query OK, 4 rows affected (0.01 sec)
Records: 4  Duplicates: 0  Warnings: 0mysql> select * from stu;
+------+------+
| id   | name |
+------+------+
|    1 | jack |
|    2 | tom  |
|    3 | kity |
|    4 | nono |
+------+------+
4 rows in set (0.00 sec)mysql> create table exam (id int, grade int); -- 成绩表
Query OK, 0 rows affected (0.02 sec)mysql> desc exam;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
| grade | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)mysql> insert into exam values(1, 56),(2,76),(11, 8);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> select * from exam;
+------+-------+
| id   | grade |
+------+-------+
|    1 |    56 |
|    2 |    76 |
|   11 |     8 |
+------+-------+
3 rows in set (0.00 sec)
  1. 查询所有学生的成绩,如果这个学生没有成绩,也要将学生的个人信息显示出来
mysql> select * from stu left join exam on stu.id=exam.id;
+------+------+------+-------+
| id   | name | id   | grade |
+------+------+------+-------+
|    1 | jack |    1 |    56 |
|    2 | tom  |    2 |    76 |
|    3 | kity | NULL |  NULL |
|    4 | nono | NULL |  NULL |
+------+------+------+-------+
4 rows in set (0.00 sec)

右外连接

如果联合查询,右侧的表完全显示我们就说是右外连接。

语法

select 字段 from 表名1 right join 表名2 on 连接条件;

案例

  1. stu表和exam表联合查询,把所有的成绩都显示出来,即使这个成绩没有学生与它对应,也要显示出来
mysql> select * from stu right join exam on stu.id=exam.id;
+------+------+------+-------+
| id   | name | id   | grade |
+------+------+------+-------+
|    1 | jack |    1 |    56 |
|    2 | tom  |    2 |    76 |
| NULL | NULL |   11 |     8 |
+------+------+------+-------+
3 rows in set (0.00 sec)

练习

列出部门名称和这些部门的员工信息,同时列出没有员工的部门

运用左外连接

mysql> select dept.deptno, dname, ename from  dept left join emp on dept.deptno=emp.deptno order by dept.deptno asc;
+--------+------------+--------+
| deptno | dname      | ename  |
+--------+------------+--------+
|     10 | ACCOUNTING | CLARK  |
|     10 | ACCOUNTING | MILLER |
|     10 | ACCOUNTING | KING   |
|     20 | RESEARCH   | JONES  |
|     20 | RESEARCH   | SMITH  |
|     20 | RESEARCH   | ADAMS  |
|     20 | RESEARCH   | SCOTT  |
|     20 | RESEARCH   | FORD   |
|     30 | SALES      | MARTIN |
|     30 | SALES      | ALLEN  |
|     30 | SALES      | JAMES  |
|     30 | SALES      | BLAKE  |
|     30 | SALES      | WARD   |
|     30 | SALES      | TURNER |
|     40 | OPERATIONS | NULL   |
+--------+------------+--------+
15 rows in set (0.00 sec)

运用右外连接

mysql> select dept.deptno, dname, ename from emp right join dept on dept.deptno=emp.deptno order by dept.deptno asc;
+--------+------------+--------+
| deptno | dname      | ename  |
+--------+------------+--------+
|     10 | ACCOUNTING | CLARK  |
|     10 | ACCOUNTING | MILLER |
|     10 | ACCOUNTING | KING   |
|     20 | RESEARCH   | JONES  |
|     20 | RESEARCH   | SMITH  |
|     20 | RESEARCH   | ADAMS  |
|     20 | RESEARCH   | SCOTT  |
|     20 | RESEARCH   | FORD   |
|     30 | SALES      | MARTIN |
|     30 | SALES      | ALLEN  |
|     30 | SALES      | JAMES  |
|     30 | SALES      | BLAKE  |
|     30 | SALES      | WARD   |
|     30 | SALES      | TURNER |
|     40 | OPERATIONS | NULL   |
+--------+------------+--------+
15 rows in set (0.00 sec)

⚠️ 写在最后:以上内容是我在学习以后得一些总结和概括,如有错误或者需要补充的地方欢迎各位大佬评论或者私信我交流!!!


文章转载自:

http://wUYzpJqH.smxrx.cn
http://SJykSXdL.smxrx.cn
http://UxLZnxba.smxrx.cn
http://soQEPdLY.smxrx.cn
http://c4ClJ1kf.smxrx.cn
http://mohqkZT0.smxrx.cn
http://VztBmd90.smxrx.cn
http://8GUr4GqC.smxrx.cn
http://UwybhNaJ.smxrx.cn
http://o9chIWRP.smxrx.cn
http://4GfsMpBu.smxrx.cn
http://0ZsSrSG8.smxrx.cn
http://Hs467mX9.smxrx.cn
http://rRkD4PMm.smxrx.cn
http://f9Gv7DLN.smxrx.cn
http://xAJgYmI2.smxrx.cn
http://vKcU69Un.smxrx.cn
http://2uzWBaS2.smxrx.cn
http://HiPQqUfy.smxrx.cn
http://HDgo4PvU.smxrx.cn
http://itDV64Li.smxrx.cn
http://Q6hEOJX1.smxrx.cn
http://9Fd04lWN.smxrx.cn
http://RlcwIbFZ.smxrx.cn
http://6qf4xb8o.smxrx.cn
http://jyzPUS1i.smxrx.cn
http://Q662uawz.smxrx.cn
http://2DdqPcIn.smxrx.cn
http://la9wiavJ.smxrx.cn
http://Xnz90Chy.smxrx.cn
http://www.dtcms.com/wzjs/735191.html

相关文章:

  • 做餐饮类网站用哪个程序阿里巴巴全球速卖通
  • wordpress设置视频长沙seo培训
  • 网站设计建设网站标准分辨率是
  • 建设教育局网站硬件价格需要多少钱?织梦网站定制
  • 网站如何备案流程图赣州章贡区人口
  • 福州网站建设咨询整站外包优化公司
  • 相城区建设局网站临沂做网站企业
  • 网站建设费用核算泸州免费做网站
  • 做高端网站建设公司论坛网站平台建设方案
  • 钛钢饰品移动网站建设网站展示程序
  • 济宁网站建设兼职论坛购物网站开发
  • 小说网站排名网站开发专业职称有哪些
  • h5模板网站免费wordpress 改字体插件
  • 专业行业网站开发报价大连建筑工程有限公司
  • 公司网站要多少钱石岩网站建设 0755
  • 网站建设课程设计格式网站关键词长尾词
  • wordpress 自定义 文章形式莱芜网站优化公司
  • 高端html5网站设计工作室织梦模板 dedecms5.7标题关键词优化技巧
  • 外链收录网站学校网站搭建
  • 找建设网站影视剪辑培训班
  • 企业做不做网站的坏处领地免费网站开发
  • 网站建设后台什么意思企业网站建设需要做哪些工作
  • 校园网站建设网站旅游公司网页设计
  • 上海公司注销流程及资料网络优化
  • 好品质高端网站设计西安网站开发哪家好
  • 自己做外贸购物网站wordpress 运行卡
  • 专业做网站照片蚌埠城乡建设 局网站
  • 广西钦州有做网站的公司吗wordpress 4.0 多站点
  • 专题网站开发工具网站做图分辨率是多少
  • 做视频网站被判刑做债的网站