数据库检索(Select)

2016-11-15  本文已影响0人  olivia_ong

基本检索

带有特定功能的检索

select distinct column_name 
from table_name;
select column_name1 
from table_name 
order by column_name2;//按照column_name2对column_name1排序

2.降序排序

select column_name1 
from table_name 
order by column_name2 desc;
select column_name from table_name limit offset;//从第一行开始返回不超过offset行
select column_name from table_name **limit** begin,n;//从begin+1行开始检索n行(begin从0开始)
=select column_name from table_name **limit** n **offset** begin;

嵌套检索(子查询)

嵌套在其他查询中的查询

select cust_id
from orders
where order_num in ( select order_num
                     from orderitems
                     where prod_id='TNT2');
select cust_name,
         cust_state,
         (select count(*)
          from orders
          where orders.cust_id=customers.cust_id) as orders
from customers
order by cust_name;

组合查询

select vend_id,prod_id,prod_price
from products
where prod_price<=5
union
select vend_id,prod_id,prod_price
from products
where vend_id in (1001,1002);

利用联结的查询

全文本搜索

上一篇下一篇

猜你喜欢

热点阅读