Mysql 系列文章主页 =============== 1 准备数据 1.1 建立 Employee 表 DROP TABLE IF EXISTS employee; CREATE TABLE IF NOT EXISTS employee( id INT PRIMARY KEY auto_increment, name ), dept_id INT ); ); ); ); ); 1.2 建立 Department 表 DROP TABLE IF EXISTS department; CREAT…
看看下面三个关联查询的 SQL 语句有何区别? 1SELECT * FROM film JOIN film_actor ON (film.film_id = film_actor.film_id) 2SELECT * FROM film JOIN film_actor USING (film_id) 3SELECT * FROM film, film_actor WHERE film.film_id = film_actor.film_id 最大的不同更多是语法糖,但有一些有意思的东西值得关注.…
内连接 SELECT <select_list> FROM TableA A INNER JOIN TableB B ON A.Key = B.Key 左外连接 SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key WHERE B.Key IS…
规定:左边的圆代表表 a,右边的代表 b. JOIN 关键字可以在两表之间选中任意部分.] 通过以下代码制造一些数据: delimiter // drop procedure if exists produce_data// create procedure produce_data() begin ; drop table if exists a; drop table if exists b; )); )); ; do insert into a(id,name) values(i, con…
一. select * from A inner join B on A.key = B.key 二. select * from A left join B on A.key = B.key 三. select * from A right join B on A.key = B.key 四. select * from A left join B on A.key = B.key where b.key is null 五. select * from A right join B on A…
1. 内连接 select * from A inner join B where A.key=B.key; 2. 左连接 select * from A left join B on A.key=B.key where B.key is null; 3. 右连接 select * from A right join B on A.key=B.key where A.key is null; 4. 左外连接 select * from A left join B on A.key=B.key;…
个人平时记录的,有点乱 1.修改时间字段,如果时间字段的类型是date或者是datetime类型的 update 表名 set 时间字段 = DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s') where id = 110 2.查询时间格式为date或者datetime类型的数据,用时间做条件的 select * from 表名 where date_format(时间字段,'%Y-%m-%d') = '2016-12-10' 3.替换某个字段中的指定字符或数据 upd…