插入数据:
插入多条数据
INSERT INTO table_name(field1,field2 ) VALUES ( valueA1,valueA2),(valueA1,valueA2)
插入一条数据
INSERT INTO table_name(field1,field2 ) VALUES ( valueA1,valueA2)
查询:
无条件查询一个表中所有数据
select * from table_name
逻辑运算符查询
and
or
not
select * from table_name where condition1 and condition1
范围查询
in
between a and b 包含a 和b
select * from table_name where condition1 in ()
模糊查询
like
select * from table_name where condition1 like
限制条数
limit
select * from table_name where condition1 limit 4, 1; // 从第五条开始显示,显示1条
排序
desc降序
asc 升序
select * from table_name where condition1 order by column desc // 降序
联合查询
userid | username | password |
1 | test | 111111 |
2 | jane | 111111 |
表1
userid | level |
1 | 15 |
2 | 20 |
表2
内联查询
eg:两个表中都存在userid相等的拼成一行
select * from T1 inner join T2 on T1.userid=T2.userid
左联
eg:显示表1 中所有的行,并把比表2 中符合条件的拼接在一起,表2 中不符合条件返回的null
select * from T1 left out join T2 on T1.userid=T2.userid
右联
select * from T1 right out join T2 on T1.userid=T2.userid