Jump to content

W3Schools & SQL Subqueries?


davej
 Share

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? Edited by davej
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...