检索表中的所有数据
select * from table_name
检索表中的数据并最多显示5行
select * from table_name limit 5
去重
select distinct 字段 from table_name
排序
select * from table_name order by 字段
分组
select * from table_name group by 字段
判断条件
select * from table_name where xxxxxx
自联结
select p1.scores,p1.id from scores as p1 ,scores as p2 where p1.stu_id = p2.stu_id and p2.id = 2;
左外联结
select students.name,scores.score from students left outer join scores on students.stu_id = scores.stu_id and scores.score < 60;
内联结
select students.name,scores.score from students inner join scores on students.stu_id = scores.stu_id and scores.score < 60; 内联结
子查询
select name from students where stu_id in (select stu_id from scores where score < 60);
视图
reate or replace view 视图名 as
查看索引
show index from table_name
创建索引
create index name_index on table_name
删除索引
drop index name_index on table_name
网友评论