檢索表中的所有數(shù)據(jù)
select * from table_name
檢索表中的數(shù)據(jù)并最多顯示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
自聯(lián)結
select p1.scores,p1.id from scores as p1 屿衅,scores as p2 where p1.stu_id = p2.stu_id and p2.id = 2;
左外聯(lián)結
select students.name,scores.score from students left outer join scores on students.stu_id = scores.stu_id and scores.score < 60;
內(nèi)聯(lián)結
select students.name,scores.score from students inner join scores on students.stu_id = scores.stu_id and scores.score < 60; 內(nèi)聯(lián)結
子查詢
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
創(chuàng)建索引
create index name_index on table_name
刪除索引
drop index name_index on table_name