sql subqueries code example
Example 1: NESTED QUERY SQL
SELECT column_name [, column_name ]
FROM table1 [, table2 ]
WHERE column_name OPERATOR
(SELECT column_name [, column_name ]
FROM table1 [, table2 ]
[WHERE])
Example 2: mssql subqueries
USE AdventureWorks2016;
GO
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;
GO
Example 3: what is subquery in sql
SUBQUERY IS NESTED QUERY INSIDE A SELECT,
INSERT OR UPDATE METHODS. OR INSIDE ANOTHER SUBQUERY
Example 4: querying in subquries sql
SELECT column-names FROM table-name1 WHERE value IN (SELECT column-name FROM table-name2 WHERE condition)
Example 5: select in select sql
SELECT column1 = (SELECT column-name FROM table-name WHERE condition), column-names FROM table-name WEHRE condition
Example 6: subquery sql
UPDATE Book SET note= 'editore: ' + (SELECT name FROM Publisher WHERE Publisher.ID = Book.publisher)