How is subquery used in sqlserver?I mean the command used for subquery?
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)
*** Innila ***
A correction,
It is not true that A subquery is a SELECT query that returns a single value. Subquery can also return set of values... Here is an example,
SELECT ename, empno, sal from Northwind.emp_new a
where sal in (SELECT MAX(sal) FROM Northwind.emp_new b group by dept)
Yeah true.
Nice that u have mentioned the correction, James.
*** Innila ***