MySQL 基本语句记录

来源:互联网 发布:淘宝自动分销怎么取消 编辑:程序博客网 时间:2024/06/06 09:30
-- 查询
select column1,column2 from table
select column1,column2 from table where id = 1


-- 插入
insert into table (column1,column2) values (column_value1,column_value2)


-- 更新
update table set column1 = 'column_value1',column2 = 'column_value2' where id = 1


-- 删除
delete from table where id = 1


-- 内连接查询

select * from table1,table2 where table1.id = table2.id
select * from table1 inner join table2 on table1.id = table2.id


-- 左右连接查询
select * from table1 right join table2 on table1.id = table2.id
select * from table1 left join table2 on table1.id = table2.id


-- 全连接查询
select * from table1 right join table2 on table1.id = table2.id
union
select * from table1 left join table2 on table1.id = table2.id


-- 排序
select * from table1 order by id
select * from table2 order by id desc


-- 统计
select max(id) from table1
select min(id) from table1
select sum(id) from table1
select avg(id) from table1
select count(id) from table1 where pid = 1
select count(id) from table1 where table1.pid = table2.pid group by table1.pid 


-- 限制查询
select * from table1 limit 0,5
0 0
原创粉丝点击