Jump to content

W3Schools & SQL Subqueries?


davej

Recommended Posts

  • 2 weeks later...
This is where I first learned SQL, and it includes subqueries. It's not perfect, but it's good for a beginner.
I don't see much there about subqueries. There is some info here;http://msdn.microsoft.com/en-us/library/ms175838.aspxI also wonder if a subquery is always or generally more efficient that the equivalent join?Example;SELECT O.ORDER_ID, O.ORDER_DATEFROM ORDERS OWHERE ORDER_ID IN (SELECT ORDER_ID FROM SALES WHERE CUST_ID IN (SELECT CUST_ID FROM CUSTOMER WHERE Phone = '1231234567' ));...or a 3-way inner join...SELECT DISTINCT O.ORDER_ID, O.ORDER_DATEFROM ORDERS O, SALES S, CUSTOMER CWHERE O.ORDER_ID = S.ORDER_ID AND O.CUSTOMER_ID = C.CUSTOMER_ID AND C.Phone = '1231234567'; Both produce the same results, but is one better, faster, or more efficient?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...