MySQL retrieve data

  1. Retrieve a single column
-- 检索单个列
SELECT prod_name FROM products

Insert picture description here

  1. Retrieve multiple columns
-- 2.检索多个列
SELECT prod_id, prod_name, prod_price FROM products;

Insert picture description here
3. Retrieve all columns

-- 3.检索所有列
SELECT * FROM products;

Insert picture description here
4. Retrieve different values

-- 4. 检索不同的值
SELECT DISTINCT vend_id FROM products;

Insert picture description here
5. The two columns after DISTINCT are not exactly the same, so all rows are retrieved

-- DISTINCT后的两列不完全相同,所以所有的行都被检索出来
SELECT DISTINCT vend_id, prod_price FROM products;

Insert picture description here
6. Sort the data

-- 6. 排序数据
SELECT prod_name FROM products ORDER BY prod_name;

Insert picture description here
7. Sort by multiple columns

-- 按多个列排序
SELECT prod_id, prod_price, prod_name FROM products ORDER BY prod_price, prod_name

Insert picture description here
8. Specify the sort direction

-- 8. 指定排序方向
SELECT prod_id, prod_price, prod_name FROM products ORDER BY prod_price DESC

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_37335220/article/details/112094277