Find jobs | Jobseekers
Employer login
About us Sitemap of www.CareerRide.com Sitemap FAQ related with www.CareerRide.com FAQ Click here to Contact us Contact
       
Submit Resume Free ! | Access Resume Free !
Home Career Services Resume Services Interview questions Articles Books
Content
SQL Server part 1
SQL Server part 2
SQL Server part 3
SQL Server part 4
SQL Server part 5
SQL Server part 6
SQL Server part 7
SQL Server part 8
SQL Server part 9
SQL Server cursor
SQL Server replication
Structured query language
SQL Server architecture
SQL Server constraints
SQL Server cursors
Data Mining
Data warehousing
SQL Server DTS
SQL Server functions
SQL Server indexes
SQL Server joins
SQL Server locks
SQL Server Net integration
SQL Server optimization
SQL Server replication
SQL reporting services
SQL service broker
SQL Server stored procedures
SQL Server table
SQL Server transactions
SQL Server transactions Architecture
SQL Server triggers
SQL Server views
SQL Server XML integration
SQL Server DDL
SQL Server DML
SQL Server DCL
SQL Server identifier
SQL Server data integrity
SQL Server accessing data
SQL Server subqueries
SQL Server cube operator
SQL Server insert data
SQL Server distributed queries
SQL Server index tuning
 
ASP.NET | ADO.NET | AJAX
C#.NET | VB.NET | PHP
NET Remoting | NET Interview
  
C | C++ | Java | Oops
Data Structure | OS
   
Database concepts | Oracle
SQL Server | Biztalk | Sharepoint
Notification services
Reporting Services
Service-oriented architecture
Data warehousing | MySQL
  
Project Management 
Linux | Testing | Networking
Software engineering 
  
UML | XML | HTML | SOAP 
CSS | VBScript  | Web Services
   
CV Cover letter | Interview 
HR | Soft skills | GD 
Working from Home 
Tutorial
ASP.NET | VB.NET | C#.NET     
Remoting.NET | Web service
Remoting overview | ADO.NET
UML | Sql server 
More links
How to transfer or export SQL Server 2005 data to Excel 
Books on SQL Server
Beginners Guide to SQL Server Integration Services Using Visual Studio 2005 

SQL Server data definition language


SQL Server Subqueries interview questions

<<Previous  Next>>

SQL Server Subqueries - Nov 20, 2008 at 18:00 PM by Rajmeet Ghai

Define Subqueries.

A subquery is a query within a query. These sub queries are created with SQL statements. These subqueries are embedded within SELECT, FROM or the WHERE clause.

Explain with examples for the Subqueries with IN and NOT IN.

Sub Query Example with IN: Displays employees from employee table with bonus > 1000. Using IN first all employees are selected and compared to each row of the subquery. Select first_name from employee

Where bonus_id IN (select id from bonus Where bonus_amt > 1000);

Sub Query Example with NOT IN: Displays employees from employee table with bonus < 1000. Using NOT IN first all employees are selected and compared to each row of the subquery.

Select first_name from employee Where bonus_id NOT IN (select id from bonus Where bonus_amt < 1000);

Explain the subqueries with comparison operators.

Answer
Comparison operators can be used (like <, >, =, !> etc). Sub queries used with comparison operators must return a single value rather than a list to avoid error. Hence the nature of the database must be knows before executing such sub queries.

Example: To display employees who have been referred by John whose id 276

SELECT employeeID FROM employee. employee_name WHERE referenceID = (SELECT referenceID FROM employee.firstname WHERE EmpID = 276)

Example: names of all employees whose salary is greater than the average salery

SELECT Employee_ID FROM Employee.Emp_name WHERE salary > (SELECT AVG (salary) FROM Employee.Emp_name)

Explain with examples for the Subqueries with Exists and NOT Exists.

Answer
A subquery with Exist does not really return any data; it returns TRUE or FALSE.

Example: This select statement will return all records from the sales table where there is at least one record in the orders table with the same sales _id.

SELECT * FROM sales WHERE EXISTS (select * from orders where sales.sales_id = orders.sales_id);

Example for NOT EXIST: This query will work exactly the opposite to above. I.e except for the sane sales_id all other records will be returned

SELECT * FROM sales WHERE NOT EXISTS (select * from orders where sales.sales_id = orders.sales_id);


<<Previous  Next>>


 
Today's Hot Jobs
C++  SQL Server
.NET  Java  Oracle
Finance  Marketing
Seekers  Employers
Copyright © 2008 CareerRide.com. All rights reserved.