Java学习笔记

MySQL基础--3

2016-10-27  本文已影响31人  Czw_hacker

分组统计

子查询

连接查询

Paste_Image.png Paste_Image.png

> SELECT ts.id AS 'stuid',stu_name,tc.id AS 'class_id',class_name
> FROM t_student AS ts,t_class AS tc
> WHERE ts.class_id = tc.id

 (ts为表一名字,tc为表二名字)

内连接 inner join
> SELECT ts.id AS ' stuid',stu_name,tc.id AS 'class_id',class_name
> FROM t_student AS ts
> INNER JOIN t_class AS tc
> ON ts.class_id = tc.id

(ts为表一名字,tc为表二名字)
Paste_Image.png

> SELECT ts.id AS ' stuid',stu_name,tc.id AS 'class_id',class_name
> FROM t_student AS ts
> LEFT JOIN t_class AS tc
> ON ts.class_id = tc.id

(ts为表一名字,tc为表二名字)
左连接会显示左表的所有数据
Paste_Image.png

> SELECT ts.id AS ' stuid',stu_name,tc.id AS 'class_id',class_name
> FROM t_student AS ts
> RIGHT JOIN t_class AS tc
> ON ts.class_id = tc.id

(ts为表一名字,tc为表二名字)
右连接会显示右表所有信息
上一篇下一篇

猜你喜欢

热点阅读