SQL的基本查询语句(mysql多表联查。。)
先记一下sql语句。。
真怕有一天忘记了sql语句。。
数据库分为:SQLserver,MySQL,Oracle
一、SQLserver
1、查询:
select * from Table1 a where Column=???; //
select top2 from Table1 where Column=???; //查询前两行数据
select * from Table1 where Column like '%???%' //模糊查询
select column1,* from table1 // column1可以是你想看的某列
多表联查:
select * from Table1 a
left join Table2 b
on a.Column = b.Column
where a.Column=??? and b.Column=???;
2、修改
update Table1 set Column=??? where Column=???;
3、删除
delete * from TableName ; //删除表中的数据
delete * from TableName where Column=111; //删除某列的数据
drop TableName ;//删除表
4、插入数据
insert into Table1
values ('','','','',) //根据表内多少列数据,及数据类型插入不同类型的数据
二、MySQL
多表联查:
表联查(mysql),最简单的表联查
select * FROM tableA a,tableB b
where a.tableBid=b.id
and ~;
SELECT bd.* FROM bas_employee_dept bed LEFT JOIN bas_dept bd
ON bed.dept_id=bd.id
WHERE bd.ou_id=1358 AND bd.is_deleted= 0
SELECT s.user_code, s.display_name FROM scy_user s RIGHT JOIN (SELECT bs.`employee_id` ,be.`employee_name` FROM bas_employee_shop bs LEFT JOIN bas_employee be ON bs.employee_id=be.id
WHERE bs.group_id =61 AND bs.is_deleted=0 AND bs.shop_id=7027
) c ON s.employee_name=c.employee_name WHERE group_id=61 AND s.is_deleted=0
4表联查(mysql):(从大佬那学来的~简洁明了,舒服~)
SELECT a.display_name,a.employee_name,d.dept_name FROM scy_user a
LEFT JOIN
bas_employee b ON a.employee_id = b.id
LEFT JOIN
bas_employee_dept c ON b.id=c.employee_id
LEFT JOIN
bas_dept d ON c.dept_id = d.id
WHERE
a.group_id=61 AND a.is_deleted=0
三、Oracle
Oracle不记得了。。。想起来在写,哈哈。。。