Can we write subqueries between SELECT and FROM

I want to know how to write a subquery between SELECT and FROM as

SELECT Col_Name,(Subquery) From Table_Name Where Some_condition 
+6
sql sql-server tsql subquery sql-server-2005
source share
2 answers

It:

 SELECT y.col_name, (SELECT x.column FROM TABLE x) AS your_subquery FROM TABLE y WHERE y.col = ? 

... is a typical subquery in a SELECT . Some call it a "subtitle." It:

 SELECT y.col_name, (SELECT x.column FROM TABLE x WHERE x.id = y.id) AS your_subquery FROM TABLE y WHERE y.col = ? 

... is a correlated subquery. It correlates because the result of the subquery refers to the table in the external query ( y in this case).

Effectively just write any optional SELECT statement you want in the SELECT clause, but it must be surrounded by parentheses.

+6
source share

you can do this, but you must use an alias to subquery

 SELECT Col_Name,(Subquery) as S From Table_Name Where Some_condition 
+2
source share

All Articles