第一部分 基本SELECTcode
1.1 檢索單列blog
> SELECT 列名 FROMM 表名;排序 |
1.2 檢索多列ip
> SELECT 列名1, 列名2, 列名3...get FROM 表名;io |
1.3 檢索全部的列table
> SELECT * FROM 表名;class |
1.4 去除重複列DISTINCT: 去除重複行date
> SELECT DISTINCT 列名 FROM 表名;im |
1.5 限制檢索數
> SELECT 列名 FROM 表 LIMIT 4; |
1.6 基本排序
升序: 默認 <ASC>(ascending order); 降序:**DESC**(descending order); > SELECT * FROM books ORDER BY book_id; +---------+------------------+------------------+------------------+-------------+----------+------+ | book_id | book_name | book_author_name | publication_date | description | classify | c | +---------+------------------+------------------+------------------+-------------+----------+------+ | 1 | 跟我學MariaDB | NULL | 2016-12-03 | NULL | 18 | NULL | | 2 | NodeJS | NULL | 2016-12-02 | NULL | 18 | NULL | | 3 | HTTP權威指南 | NULL | 2002-01-01 | NULL | 18 | NULL |
> SELECT * FROM books ORDER BY book_id DESC; +---------+------------------+------------------+------------------+-------------+----------+------+ | book_id | book_name | book_author_name | publication_date | description | classify | c | +---------+------------------+------------------+------------------+-------------+----------+------+ | 22 | 巨人的隕落 | NULL | 2016-05-01 | NULL | 11 | NULL | | 21 | 史記 | NULL | 1982-11-01 | NULL | 11 | NULL | | 20 | 國史大綱 | NULL | 2013-08-01 | NULL | 11 | NULL | | 19 | 人類簡史 | NULL | 2014-11-01 | NULL | 11 | NULL | |