select DISTINCT vend_id FROM products; DISTINCT去重复的值,必须放在列名前面
select prod_name from products LIMIT 5; 限制结果 LIMIT
LIMIT 4 OFFSET 3 :从行3开始取4行,== LIMIT 3,4
select acct_key.acct_name from eyou_mail.acct_key; 直接取值数据库的表内容
select prod_name from products ORDER BY prod_name; ORDER BY 进行排序
select prod_id,prod_price,prod_name from products ORDER BY prod_price,prod_name;
检索3个列,并按照其中两个列对结果进行排序------首先按价格,然后按名称排序
ORDER BY 可以降序(Z到A)顺序排序,必须制定关键字 DESC。
按照价格以降序排序产品:
select prod_id,prod_price,prod_name From products ORDER BY prod_price DESC;
ORDER BY子句的位置 : 保证它位于FROM子句之后。如果使用LIMIT,它必须位于ORDER BY之后.
select prod_name,prod_price from products where prod_price = 2.50;
select prod_name,prod_price FROM products Where prod_price BETWEEN 5 AND 10;
select prod_name from products where prod_price IS NULL;
OR与AND不同,它只是mysql检索匹配任意条件的行
Seletc prod_name,prod_price FROM products where vend_id = 1002 OR vend_id = 1003;
select prod_name,prod_price From products WHER (vend_id = 1002 OR vend_id =1003) AND prod_price >= 10;
select prod_name,prod_price from products where vend_id IN (1002,1003) ORDER BY prod_name;
本文出自 “我是小白” 博客,请务必保留此出处http://878045653.blog.51cto.com/2693110/1529831
原文地址:http://878045653.blog.51cto.com/2693110/1529831