Subquery: Independent subquery Dependent subquery SELECT * FROM (select Col1,col2 from TBL) as Tb1, a query results as a data source for another query, the subquery data source must be aliased as TbsSELECT * FROM (Select fname, Fage,fgender from mystudent where Fage between and fgender= ' women ')As Tbswhere fname like '% Zhao '2. As a columnSelect Highest score = Select Max (score) from Tbs,minimum min. =select min (score) from Tbs,
avg. =select avg (score) from Tbs3. Query results as query criteriaSelect * from tblstudentwhere tsclassid= (select Tsclassid form tblclass where className = ' high 22 shifts ')
4. Subqueries can only return a single valueSELECT * from TBLs where classId in (select ClassId from Tbs where classid= ' 4 ' or classid= ' 5 ')5, exists contained in the query found the result is exists return true, otherwise false
if (exists (SELECT * from TBL where 1<>1))
begin
print ' have result '
end
Els E
begin print ' No results '
end
SELECT * from TBL where exists ( SELECT * from TBL1 where name= ' high class 22 ' and Tbl.classid=tbl1.classid
SELECT *, Row_number () over (order by fid DESC) as number from TB
20 pages, 5 per page select * FROM (select *,row_number () over (order by FID DSC) as number from Tb
) as Tbnew where Tbnew.number between 19*5+1 and 20*5
row_number () line number
SELECT *, COUNT (*) from TBL (Error) SELECT *, COUNT (*) over () as total number of bars from TBL
From for notes (Wiz)
Dark Horse Video-sub Query