SQL multi-table join query instance

Source: Internet
Author: User

SQL multi-table join query instance

The following provides four SQL multi-table join query instances, with different efficiency.

Select * from order_info as a, ivrlog4ivrdlvinst as B

Where

(A. saleorder = B. ext1_skill and B. start_date = @ date1 and se_id = '55' and B. ext1_skill! = '')

And convert (varchar (10), a. instime, 112) = @ date2 and max (a. instime)

Method 2

Select * from order_info as

Where a. saleorder = (

Select B. ext1_skill from ivrlog4ivrdlvinst as B

Where B. start_date = @ date1 and se_id = '55'

And B. ext1_skill! = '')

And convert (varchar (10), max (a. instime), 112) = @ date2

Method 3

Declare

@ Date1 varchar (20 ),

@ Date2 varchar (20)

Set @ date1 = '000000'

Set @ date2 = '2017-08-12'

Select * from order_info as

Where a. saleorder =

(Select B. ext1_skill from ivrlog4ivrdlvinst as B where B. start_date = @ date1 and se_id = '55' and B. ext1_skill! = '')

And convert (varchar (10), a. instime, 112) = @ date2

And max (a. instime)

Method 4

Select B. caller, B. start_date, B. start_time, B. ext1_skill,

C. deliveryno, c. destroyresult, c. deliverydate, c. deliverytime, c. arrangetime, c. driverphone, c. drivermobile,

A. servicedate, a. servicetime, a. workertel

From order_info as a, ivrlog4ivrdlvinst as B, delivery_info as c

Where

A. saleorder in (select B. ext1_skill from ivrlog4ivrdlvinst where B. start_date = @ date1 and B. se_id = '55' and B. ext1_skill! = '')

And convert (varchar (10), a. instime, 112) = @ date2

Order by B. start_date desc, B. start_time desc

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.