SQL语句之增删查改、多表查询,模糊查询

现有数据库test,有两张表account、account_name,如下乃查询语句:

use test;
/*查询前3条数据*/
/*select * from account order by id asc limit 0,3;*/

/*查询后3条数据*/
/*select * from account order by id desc limit 0,3;*/

/*查询结果不显示重复记录条数,如果username重复则显示第一条记录*/
/*select distinct username from account;*/

/*查询不重复记录*/
/*select id,username,password from account group by username*/

/*查询记录条数*/
/*select count(*) from account where id>4*/

/*交叉连接*/
/*select account.id, account.username, account.password, account_name.name 
from account cross join account_name where account.id=account_name.id;*/

/*% 模糊查询某列是否含有对应字符,查询password含有15的密码*/
/*select * from account where password like '%15%';*/

/*_ 匹配单个任意字符,通常用来限制表达式的字符长度,三位密码,中间必须是5*/
/*select * from account where password like '_5_';*/

/*[] 中括号内为一个集合,选择其中任意一个与中括号外组成一个结果,将找出张三、李三、王三*/
/*select * from account_name where name like '[张李王]三';*/

/*[^] 表示不在括号内的单个字符与括号外组成一个查询结果*/
/*select * from  account_name where name like '[^王]三';*/


你可能感兴趣的:(SQL语句之增删查改、多表查询,模糊查询)