About 1,190,000 results
Open links in new tab
  1. Nested select statement in SQL Server - Stack Overflow

    Conceptually, the subquery results are substituted into the outer query. As we need a table object in the outer query, we need to make an alias of the inner query. Statements that include a subquery usually take one of these forms: WHERE expression [NOT] IN (subquery) WHERE expression comparison_operator [ANY | ALL] (subquery)

  2. How to Use a Subquery in a SELECT Statement - GeeksforGeeks

    Jan 2, 2025 · In this article, We will learn about Subquery in a SELECT statement by understanding various examples and output in detail. A subquery (also known as a nested query or inner query) is a query placed inside another query. The subquery returns a result that is used by the outer query.

  3. Nested Queries in SQL - GeeksforGeeks

    Apr 11, 2025 · A nested query (also called a subquery) is a query embedded within another SQL query. The result of the inner query is used by the outer query to perform further operations. Nested queries are commonly used for performing calculations, filtering data , or joining datasets indirectly without explicitly using joins

  4. SQL Nested subquery - w3resource

    May 22, 2024 · SQL has an ability to nest queries within one another. A subquery is a SELECT statement that is nested within another SELECT statement and which return intermediate results. SQL executes innermost subquery first, then next level. See the following examples :

  5. Subqueries (SQL Server) - SQL Server | Microsoft Learn

    Nov 22, 2024 · In this example, a subquery is used as a column expression named MaxUnitPrice in a SELECT statement. SELECT Ord.SalesOrderID, Ord.OrderDate, (SELECT MAX(OrdDet.UnitPrice) FROM Sales.SalesOrderDetail AS OrdDet. WHERE Ord.SalesOrderID = OrdDet.SalesOrderID) AS MaxUnitPrice. FROM Sales.SalesOrderHeader AS Ord;

  6. SQL Subquery – How to Sub Query in SELECT Statement

    Oct 4, 2022 · SQL admins usually use subqueries inside the WHERE clause to narrow down the result of the main query (or outer query). You usually put subqueries inside brackets and you can use them with comparison operators such as =, <, >, <=, and >=.

  7. How to Use SELECT with Multiple Subqueries to Same Table in SQL

    Oct 12, 2024 · In this tutorial, we’ll explore using subqueries in SELECT, WHERE, and FROM clauses and show how to handle them when they become repetitive (and redundant). All our examples are based on our University database schema.

  8. What Is a Nested Query in SQL? - LearnSQL.com

    May 7, 2020 · By using nested SELECTs, you can filter, aggregate, and transform data in ways that provide deeper insights and more precise results. In this article, I'll explain what nested queries are, why they're useful, and how to use them efficiently.

  9. How to Use the SQL Subquery: A Detailed Guide | Codecademy

    Mar 25, 2025 · In this query: The subquery is executed first. It searches the departments table and returns the department_id of the ‘Sales’ department.; Next, the outer query is executed. It retrieves the department_id returned by the subquery and returns all employees whose department_id matches with the retrieved one.; This is how queries, including subqueries, are executed in SQL.

  10. SQL | Subquery - GeeksforGeeks

    Apr 14, 2025 · Nested Structure: A subquery is executed within the context of an outer query. Parentheses: Subqueries must always be enclosed in parentheses (). Single-Row vs. Multi-Row Subqueries: Subqueries may return a single value (e.g., a single row) or multiple values. Depending on the result, different SQL constructs may be required.

  11. Some results have been removed
Refresh