《MySQL 8创建数据库、数据表、插入数据并且查询数据》里边有我使用到的数据。
再使用下方的语句补充一些数据:
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (11,'Book Break','22245678911',18,'male','good#111');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (12,'Book Blue','58745678912',19,'female','good#113');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (13,'Book Red','58745678913',20,'male','good#112');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (14,'Jack Blue','22245678914',22,'female','good#113');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (15,'Books Rat','69845678915',24,'male','good#144');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (16,'Books Hat','69845678916',35,'female','good#133');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (17,'Books Rd','69845678917',78,'male','good#144');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (18,'Goods Rh','78945678918',89,'male','good#145');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (19,'Tim Good','00000000004',44,'female','good#112');
insert into Bookbought.bookuser(id,username,userphone,userage,sex,userpassword) values (20,'Tom Good','44444444487',47,'male','good#1178');
字段
也称为列名
。
使用下方语句为
select 列名 from 数据库名.表名
where 查询条件
having 查询条件
group 分组条件
order by 属性名 [asc | desc]
要是先使用use 数据库;
选择数据库之后,那么就可使用下方语句省略数据库名:
select 列名 from 表名
where 查询条件
having 查询条件
group 分组条件
order by 属性名 [asc | desc]
select * from [数据库.]表名;
可以查询某一个表里边所有数据,比如select * from Bookbought.bookuser;
或者select * from bookuser;
。
要是提示ERROR 1046 (3D000): No database selected
,那么需要使用use 数据库;
来选择数据库,比如use Bookbought;
select id,username from Bookbought.bookuser;
或者select id,username from bookuser;
select distinct 字段名 from 表名;
,比如select distinct sex from Bookbought.bookuser;
select 列名 from 表名
where 查询条件;
我这里举个例子,比如:
select * from Bookbought.bookuser where id = 12;
就是查询id
为21的用户。