MySQL LIMIT选择单行
要在MySQL中选择一行,可以使用LIMIT。首先,让我们创建一个表。创建表的查询如下-
mysql> create table selectWithPrimaryKey -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('Larry',24,98);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('John',23,89);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('Mike',21,85);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('Sam',26,56);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('Carol',21,59);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('Bob',20,91);
mysql> insert into selectWithPrimaryKey(Name,Age,Marks) values('David',28,93);使用select语句显示表中的所有记录。查询如下-
mysql> select *from selectWithPrimaryKey;
以下是输出-
+----+-------+------+-------+ | Id | Name | Age | Marks | +----+-------+------+-------+ | 1 | Larry | 24 | 98 | | 2 | John | 23 | 89 | | 3 | Mike | 21 | 85 | | 4 | Sam | 26 | 56 | | 5 | Carol | 21 | 59 | | 6 | Bob | 20 | 91 | | 7 | David | 28 | 93 | +----+-------+------+-------+ 7 rows in set (0.00 sec)
这是使用LIMIT从表中选择一行的查询-
mysql> select *from selectWithPrimaryKey where Id = 10 or Age = 29 or Marks = 89 limit 1;
以下是输出-
+----+------+------+-------+ | Id | Name | Age | Marks | +----+------+------+-------+ | 2 | John | 23 | 89 | +----+------+------+-------+ 1 row in set (0.00 sec)
热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短