|
|
|
Custom Search
| |
|
| |
|
Using subquery in SELECT statement and WHERE clause
Inside This Tutorial Series
Using subquery to return a single value When the subquery returns a single value, the subquery is only evaluated once and then the value is returned to outer query to use. This kind of subqueries are also known as single-value subquery or scalar subquery. The subquery can be used in either SELECT statement or WHERE clause. In either case, an aggregate function or an expression is normally used in the subquery. When the subquery is used in WHERE clause, a comparison operator is always used. Practice #1-1: Use subquery in WHERE clause with an aggregate function. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /*
Query result set - 3 rows returned: Practice #1-2: Use subquery in WHERE clause with an aggregate function. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /*
Query result set - 25 rows returned: Practice #2: Use subquery in SELECT statement with an aggregate function. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /*
Query result set - 77 rows returned: Practice #3: Use subquery and join clause. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /*
Query result set - 1 row returned:
|
|
Copyright © 2012 GeeksEngine.com. All Rights Reserved. This website is hosted by LunarPages. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
| Home | Kung Fu Timer | Feedback | Terms of Use | Privacy Policy |