1、判断登录相等

$sql ="select * from A where username='$username' and password='$password'";

tips:建议在后端只查询数据库,在前端 ajax 中进行用户登录的判断

$sql ="select * from A ";

2、注册

$sql="INSERT INTO A(id,username,password) VALUES (uuid(),'$username','$password')";

3、查询数据表 A 中 一列与数据表 B 中一列相等的数据,且按 A 表goods_max 列逆序排列 取最大的前六个

$sql="SELECT * FROM A,B WHERE A.goods_code=B.goods_code ORDER BY cast(A.goods_max as UNSIGNED INTEGER) DESC LIMIT 6 ";

tips:A.goods_max as UNSIGNED INTEGER 这句话的意思是把vachar类型变量转换为int类型变量

4、删除

$sql="delete from matching_order where file_id='$id'";

2)同时删除两个表中相同的数据

$sql="delete table_a,table_b from table_a,table_b where table_a.id=table_b.id AND table_a.id='$id'";

5、更新(更改数据表中 name =‘菜鸟教程’ 一行中的 alexa ,country列)

$sql=" UPDATE Websites SET alexa='5000', country='USA' WHERE name='菜鸟教程';";


6、对数据表中的数据做加法
(对数据表 table 中 id =5 的数据中的 number 列做加法)

$sql="update table set number= number +'1' where id='5'";

点击跳转到另一篇博客查看

7、对一数据表中各列的模糊查询

对表中每一列 包含222 的数据进行显示

select *
from 表
where 列1 like '%222%' or 列2 like '%222%' or 列3 like '%222%' or 列4 like '%222%';

更多推荐

【php】sql 常用语句(持续更新)