adspace


how many type of subquery?

Answer Posted / rajkumar

As database developer, you must have ever written
subqueries in either SQL Server or any other database
platform. This article will describe shortly about types of
subquery.


A subquery is inner query that will be used by outer query.
A subquery could return scalar value or a series of value.
Based on query dependency, a subquery could be self-
contained or correlated one. A self-contained subquery is a
subquery independent from outer query, and correlated
subquery is a subquery that is referencing to a row in
outer query.


Self-contained subquery is easier to debug than correlated
subquery. And it is executed only once whereas correlated
subquery is executed once for each row of outer query.


Sample of self-contained subquery that returns scalar value
is shown below :


Select customerid

From dbo.orders

Where employeeid = (select employeeid from dbo.employees
where lastname = ‘RAJ’);


This query returns customers list whose employee is RAJ.

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we do dml on views?

1042


How to convert character strings into numeric values?

1196


What kind of problems occurs if we do not implement proper locking strategy?

1508


Explain “row_number()” in sql server with an example?

1086


What are the kinds of subquery?

1118


How efficient you are in oracle and SQL server?

1269


What are the pros and cons of putting a scalar function in a queries select list or in the where clause?

1303


what is spatial nonclustered index

1066


What is subquery? Explain the properties of a subquery?

1070


What is sql or structured query language?

1235


what is the difference between openrowset and openquery?

1208


List out the different types of locks available in sql server?

1058


How do I create a trace in sql server?

1128


Why we use the openxml clause?

1088


Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?

1032