How is subquery used in sqlserver?I mean the command used for subquery?
Printable View
How is subquery used in sqlserver?I mean the command used for subquery?
Hi Chitra,
A subquery is a select statement that is embedded in a clause of another select statement.
A subquery is a SELECT query that returns a single value and is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery.
Here is a simple subquery example where the employee details of maximum salary holder is retrieved,
[Code]
SELECT ename, empno, sal from Northwind.emp_new a
where sal = (SELECT MAX(sal) FROM Northwind.emp_new b)
[/Code]
A correction,
It is not true that A subquery is a SELECT query that returns a[B][COLOR="Red"] single value[/COLOR][/B]. Subquery can also return set of values... Here is an example,
SELECT ename, empno, sal from Northwind.emp_new a
where sal [B]in[/B] (SELECT MAX(sal) FROM Northwind.emp_new b group by dept)
Yeah true.
Nice that u have mentioned the correction, James.