Can we rewrite subqueries into simple select statements or
with joins? Example?

Answers were Sorted based on User's Feedback



Can we rewrite subqueries into simple select statements or with joins? Example?..

Answer / divya kalra

Subqueries can often be re-written to use a standard outer
join, resulting in faster performance. As we may know, an
outer join uses the plus sign (+) operator to tell the
database to return all non-matching rows with NULL values.
Hence we combine the outer join with a NULL test in the
WHERE clause to reproduce the result set without using a
sub-query.

Is This Answer Correct ?    4 Yes 1 No

Can we rewrite subqueries into simple select statements or with joins? Example?..

Answer / syed sajjad

Yes we can write using Common Table Expression (CTE). A Common Table Expression (CTE) is an expression that can be thought of as a temporary result set which is defined within the execution of a single SQL statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Do you know what is blocking?

0 Answers  


Which tcp/ip port does sql server run on? How can it be changed?

0 Answers  


Where is trigger in sql server?

0 Answers  


How to Update from select query in sql server?

0 Answers  


what are the problems in logshipping?

3 Answers  






How to select Distinct columns from the table, table having 20 columns and i want all coulmns

5 Answers   Wipro,


What is Full Outer Join?

3 Answers  


Can we use Truncate command on a table which is referenced by FOREIGN KEY?

2 Answers   Shriram,


What does normalization do to data?

0 Answers  


This question asked during interview, 2) At the end of each month, a new table is created for each bank that contains monthly metrics consolidated at the account level. The table naming convention is bankX_YYYYMM where X represents the numeric designation of the bank and YYYYMM indicates the 4 digit year and 2 digit month. The tables contain the following fields: name data type description account text account number registered boolean indicates whether the account is registered num_trans integer number of transactions made during the time period spend numeric(9,2) total spend during the time period a) Write a SQL query that will display the total number of transactions and total spend for "Bank1" during the 4th quarter of 2009. b) Write a SQL query that will display the total number of transactions and total spend at "Bank1" and "Bank2", broken out by registered vs. non-registered accounts, during January 2010 not sure what is correct answer and how to solve?

0 Answers   TCS,


Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

0 Answers   Satyam,


How can you set the threshold at which sql server will generate keysets asynchronously?

0 Answers  


Categories