資料庫中表的複雜查詢,資料庫中表複雜

來源:互聯網
上載者:User

資料庫中表的複雜查詢,資料庫中表複雜

資料庫中表的複雜查詢1、串連查詢1.0串連的基本文法格式:from TABLE1 join_type TABLE2 [on (join_condition)][where (query_condition)]TABLE1:左表TABLE2:右表join_type:串連的類型。交叉、內串連、左外串連、右外串連on:設定串連條件where:對串連查詢的結果進步一的篩選1.1交叉串連select * from CUSTOMER cross join ORDERS;或者select * from CUSTOMER,ORDERS;select c.name,o.order_number from CUSTOMER c,ORDERS o;1.2內串連:隱式內串連:(不使用on關鍵字,使用where)select * from CUSTOMER c,ORDERS o where c.id=o.customer_id;顯式內串連:(使用on關鍵字)select * from CUSTOMER c inner join ORDERS o on c.id=o.customer_id;1.3外串連:左外串連:(返回符合串連條件的所有記錄,同時還返回左表中其餘的所有記錄)select * from CUSTOMER c left outer join ORDERS o on c.id=o.customer_id;右外串連:(返回符合串連條件的所有記錄,同時還返回右表中其餘的所有記錄)select * from CUSTOMER c right outer join ORDERS o on c.id=o.customer_id;2、子查詢(巢狀查詢)子查詢: select * from orders where customer_id=(select id from customer where name='張三');3、聯集查詢SELECT * FROM orders WHERE price>200 UNION SELECT * FROM orders WHERE customer_id=1;取兩條語句的並集,並去除重複的記錄。

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.