A subquery can also be nested inside INSERT, UPDATE, and DELETE statements. In fact, a subquery can be contained inside another subquery, which is inside another subquery, and so forth. More formally, it is the use of a SELECT statement inside one of the clauses of another SELECT statement. Subqueries enable you to write queries that select data rows for criteria that are actually developed while the query is executing at run time. If you find the article helpful, don’t hesitate to share it with your friends and family.A subquery is best defined as a query within a query. You can use subqueries in all the CRUD operations of SQL – INSERT, SELECT, UPDATE, and DELETE. However, subqueries are not limited to the SELECT statement only. This article showed you what you need to know about SQL subqueries and how to use them with the SELECT statement. WHERE name IN ('Denis Jack', 'Ola Ajayi', 'Uche Ugo') To show you that you can really use multiple values inside the WHERE clause with the help of the IN statement, I got the wage of some employees with known names by running this query: SELECT name, wage FROM employees SELECT name, country, wage FROM employees The IN statement lets you use multiple values inside a WHERE clause. To get the wage of the employees from the USA, including their names and country, I combined the WHERE clause with the IN statement. WHERE wage < (SELECT AVG(wage) FROM employees) ![]() To adjust the query so I can get data of the employees earning less than the average wage, we only need to change the greater than symbol (>) to less than (<): SELECT * FROM employees So, the query and subquery helped us get all the employees with a wage more than the average wage of 1250.0000. You can see the average wage is 1250.0000. To show you the average wage, in particular, I could run only the subquery:
0 Comments
Leave a Reply. |