MairDB 如何查询表

一、检索单列

>SELECT列名FROMM表名;

二、检索多列

> SELECT列名1,列名2,列名3...

FROM表名;

三、检索所有的列

> SELECT * FROM表名;

四、去除重复列

> SELECT DISTINCT列名FROM表名;

DISTINCT:去除重复行

五、限制检索数

> SELECT列名FROM表LIMIT 4;

刷选所用数据中的前4行;

六、基本排序

升序:默认(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|

七、按列的位置排序

SELECT book_id, book_name, description FROM books ORDER BY 2, 3;表示先按book_n

你可能感兴趣的:(MairDB 如何查询表)