Left join on[用的最多]:Select student.name,class.class_name from student left join class on class.class_num=student.class_num。左邊的為主表
Right join on: Select student.name,class.class_name from student right join class on class.class_num=student.class_num。右邊的為主表
Inner join on: Select student.name,class.class_name from student inner join class on class.class_num=student.class_num。
以誰為主表查詢誰
嵌套查詢[消耗計算機資源]:先查詢括號里邊的,再查詢外邊的。多用在多對多關系表中。
select t1.name from (select student.name,student.sno,relationship.cno from student inner join relationship on student.sno=relationship.sno) t1 where t1.cno='1001';
Insert into插入:insert into 表名(列1,列2,…) values (值1,值2,…)
如果有設置為自增的列,這一列不需要插入
插入多條:insert into 表名(列1,列2,…)values (值1,值2,…),(值1,值2,…),…
INSERT into student (name,age,sex) VALUES('張二三',18,'男');
INSERT into student (name,age,sex) VALUES('張三三',18,'男'),('張四三',18,'男'),('張五三',18,'男');
特殊插入; insert into 表名 set 列=值
INSERT into student set name='sss';
INSERT into student set name='234' where1 id=1;
Update 修改:update 表名 set 列=值,… where 列=值2。必須指定修改的行并且指定條件語句。