Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Multiple FROM keywords?

Tags:

sql

sql-server

The search term is to ambiguous for google aparently. I am looking at a SQL call and it has 2 FROM keywords? I've never seen this before, can someone explain?

SELECT TOP(5)  SUM(column) AS column, column
FROM ( SELECT DISTINCT column, column, column
FROM ((((((table table 
INNER JOIN table table ON (column = column
AND column = 2 
AND column != '' )) 
INNER JOIN table table ON (column   = column 
AND (column = 144 OR column = 159 OR column = 162 OR column = 164 OR column = 163 OR column  = 1 OR column = 2 OR column = 122 OR column = 155 OR column = 156 )))
inner join table table ON (column = column 
AND column  = 0 ))
INNER JOIN table  ON (column = column  ))
INNER JOIN table table ON ( column  = column  
AND (column   = 102 OR column  = 103 )))
INNER JOIN table table ON (column  = column  ))) TempTable  
GROUP BY column  ORDER BY column  desc 

You will note the multiple FROM keywords. It runs just fine. Just curious to what the purpose is.

like image 395
Anthony Russell Avatar asked Jan 17 '26 21:01

Anthony Russell


1 Answers

This is called as subquery. You can use subquery within your main query So subquery made the multiple FORM clause.

like image 162
Rohit Vyas Avatar answered Jan 19 '26 18:01

Rohit Vyas