MySQL基础语法
- 显示某个表的列:
show columns from customers;
- 从products表中检索三个名为prod_id, prod_name, prod_price的列:
select prod_id, prod_name, prod_price from products;
- 检索所有的列:
select * from products;
- 从products表中检索列vend_id的不同值:
select distinct vend_id from products;
- 限制返回的行数:
select prod_name from products limit 2, 5;
将会返回从第3行开始的后5行 - 使用完全限定的表名:
select products.prod_name from products;
这条语句等于:select prod_name from products;
或者:select products.prod_name from crashcourse.products;
- 检索列,并以字母顺序排序数据:
select prod_name from products order by prod_name;
- 多个列排序:
select prod_id, prod_price, prod_name from products order by prod_price, prod_name;
- 降序排列:
select prod_id, prod_price, prod_name from products order by prod_price desc;
- 先按价格降序排,再按产品名升序:
select prod_id, prod_price, prod_name from products order by prod_price desc, prod_name;
- 找出最昂贵的值:
select prod_price from products order by prod_price desc limit 1;
- 只返回prod_price值为2.50的行:
select prod_name, prod_price from products where prod_price = 2.50;