davej Posted February 19, 2011 Share Posted February 19, 2011 Am I mistaken or does the W3Schools tutorial omit all discussion of SQL subqueries?http://www.w3schools.com/sql/default.aspDoes anyone perhaps have a link to a particularly good page offering coverage of this topic? Link to comment Share on other sites More sharing options...
Fmdpa Posted February 19, 2011 Share Posted February 19, 2011 I remember viewing information on it somewhere - I thought it was the schools, but maybe it was the MySQL ref manual. Link to comment Share on other sites More sharing options...
DeathRay2K Posted March 1, 2011 Share Posted March 1, 2011 This is where I first learned SQL, and it includes subqueries. It's not perfect, but it's good for a beginner. Link to comment Share on other sites More sharing options...
davej Posted March 1, 2011 Author Share Posted March 1, 2011 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 More sharing options...
davej Posted March 1, 2011 Author Share Posted March 1, 2011 I remember viewing information on it somewhere - I thought it was the schools, but maybe it was the MySQL ref manual.This actually looks pretty good! Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.