Basic syntax for the SELECT statement:
Select selection_list//What columns to query for
from data table name//Specified data table
where primary_constraint//queries need to meet the criteria that the row must meet
group by Grouping_columns//How to Group results
order by Sorting_cloumns//How to sort the results
having Secondary_constraint//the second condition met when querying
limit count//Limit output query results
Query a data table using the SELECT statement:
When you use a SELECT statement, you first determine which column you want to query, and "*" represents all the columns in the query. For example, to query all the data in the course table in the score database, the code is as follows:
mysql> use score;database changedmysql> select * from course;+------- -+--------------+---------+---------+| cid | cname | cxueshi | teacher |+--------+--------------+---------+---------+ | 1001 | Computer Foundation | 64 | Gao Airi | | 1002 | c++ Foundation | 108 | Liu Wei | |  1003   | VB Programming | 140 | Liu Jian | | 1004 | java Diligent | 182 | Yang Wei | |  1005   | J2EE advanced Applications | 208 | Li Jianguo | | 1006 | Mathematics | 156 | Zhangxiaolei | | 1008 | Quality | 80 | Song | | 1009 | Database Fundamentals | 52 | Xue Pillar | | Meng Fanhua | English | 300 | Meng Fanhua |+--------+--------------+---------+---------+9 rows in set
This is an operation that queries all the columns in the entire table and can also be queried for one or more columns in the table
To query one or more columns in a table:
Queries are made for multiple columns in a table, as long as you specify the column name you want to query after the Select, and the multiple columns are split with ",". For example, query the CID and Cxueshi in the score table with the following code:
+--------+---------+| Cid | Cxueshi |+--------+---------+| 1001 | 64 | | 1002 | 108 | | 1003 | 140 | | 1004 | 182 | | 1005 | 208 | | 1006 | 156 | | 1008 | 80 | | 1009 | 52 | | Meng Fanhua | |+--------+---------+9 rows in Set
Get data from one or more tables:
Using a SELECT statement to query, you need to determine which table the data you want to query in, or in which tables, when querying multiple tables, use "," to separate multiple tables. For example, the values of the username, password, score, sid fields are queried from the users table and the score table.
You can also use join operations in the WHERE clause to determine the connection between tables, and then return query results based on this condition.
MySQL Basic query statement