Sub Queries-
Three basic rules only.
Where you can place sub query?
3 places where you can place your sub query:
SELECT ----- FROM
FROM ----- WHERE
WHERE ----->
SELECT ----- FROM
_____________________
(sub query can only return single value & no alias to value returned is required)
Correct:
_________
(select max(val) from abc where ---) Ex output: 10
(select top 1 val from abc where ----) Ex output: abctext
Wrong:
_________
(select val from abc where ----) and result is returning multple rows:
Ex. ouput of above query:
val
___
12
32
45
6
45
Click here to view complete article
|