Learn MySQL with teacher Wang: Basic query statement
Teacher: Wang Shaohua QQ Group No.: 483773664 Learning Content
Basic syntax for query statements
Query data refers to getting the required data from the database. In MySQL, you use the SELECT statement to query the data
The basic grammatical form of a select is as follows
1 2 3 4 5 |
SELECT属性列表
FROM表名
[ WHERE条件表达式1 ]
[ GROUPBY 属性名1 [ HAVING条件表达式2 ] ]
[ ORDERBY 属性名2 [ ASC | DESC] ]
|
Property List: The name of the field to query
Table name: The table you want to query, you can have more than one
Conditional expression 1: Specifying query criteria
Property name 1: Group By this field
Conditional expression 2: data that satisfies the expression can be output
Property Name 2: Sort by the data in this field by hundred rows
ASC: Ascending
DESC: Descending
Two examples
(i) Preparation of data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
createtableemployee(
num intprimary keyauto_increment,
namevarchar(20),
age int,
sex varchar(4),
homeaddr varchar(50)
);
insertintoemployee(name,age,sex,homeaddr)values(‘张三‘,26,‘男‘,‘浙江杭州‘);
insertintoemployee(name,age,sex,homeaddr)values(‘李四‘,24,‘女‘,‘浙江宁波‘);
insertintoemployee(name,age,sex,homeaddr)values(‘王五‘,29,‘男‘,‘浙江台州‘);
insertintoemployee(name,age,sex,homeaddr)values(‘赵六‘,21,‘男‘,‘浙江湖州‘);
insertintoemployee(name,age,sex,homeaddr)values(‘孙悟空‘,21,‘男‘,‘浙江宁波‘);
insertintoemployee(name,age,sex,homeaddr)values(‘猪八戒‘,22,‘男‘,‘浙江宁波‘);
insertintoemployee(name,age)values(‘唐僧‘,21);
|
(b) Simple Enquiry
1 |
selectnum,name,age,sex,homeaddr fromemployee;
|
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/E3/wKiom1d_MN3BOpdrAAAY_zRB17Q351.png "alt = "Wkiom1d_mn3bopdraaay_zrb17q351.png"/>
(iii) contains a WHERE clause and an ORDER BY clause
1 |
selectnum,name,age,sex,homeaddr from employee where age<26 order bynum DESC;
|
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/E2/wKioL1d_MN7wMgtRAAAa9WakBYE985.png "alt = "Wkiol1d_mn7wmgtraaaa9wakbye985.png"/>
This article is from "Learn programming with Mr. Wang" blog, please be sure to keep this source http://teacherwang.blog.51cto.com/10946447/1812576
Learn MySQL with teacher Wang: Basic query statement