ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
how to get the maximum among two tables,for example table 1 
(dep1) have (emp_id,emp_name,salary) columns and table 2 
(dept2) have (emp_id,emp_name,salary) columns,i want which 
employee have the maximum salary among two tables?
 Question Submitted By :: Sabarish.2meet
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) columns and table 2 (dept2) have (emp_id,emp_name,salary) columns,i want which employee have the maximum salary among two tables?
Answer
# 1
Use Cursors:

declare Cursor_Name cursor scroll
for 
select max(salary) as salary from dep1  
union
select max(salary) as salart from dep2 order by salary desc
open Cursor_Name 
fetch absolute 1 from Cursor_Name
deallocate Cursor_Name
 
Is This Answer Correct ?    4 Yes 0 No
Sumathy
 
  Re: how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) columns and table 2 (dept2) have (emp_id,emp_name,salary) columns,i want which employee have the maximum salary among two tables?
Answer
# 2
SELECT 
OUTERTABLE.EMPID,
MAX(OUTERTABLE.SALARY) 

FROM

(SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP1 
GROUP BY EMPID
UNION ALL
SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP2
GROUP BY EMPID) AS OUTERTABLE
GROUP BY OUTERTABLE.EMPID
 
Is This Answer Correct ?    2 Yes 1 No
Swati Tripathi
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What are the magic tables in SQL Server 2000? Infogain5
I Have Employee table having column name as ID,SALARY how to get second max salary from employee table with id ex ID SALARY 1 20000 7 37000 2 5000  11
What is a sub-query? When would you use one?  3
how to generate XML out of QUERY? McAfee1
What is the difference between UNION and UNIONALL? CTS2
MULTICAST DELEGATES IN C#.NET WITH REAL TIME EXAMPLE IBM1
what command is used to create a table by copying the structure of another table?  5
how to rest identity columns in sql server Matrix3
Name three version of sql server 2000 and also their differences?  1
What is Schema? and why we use schemas?  1
What is Deadlock? Satyam3
How to find the last update record in SQL Server?  3
What is a trigger?  6
What is an extended stored procedure? Can you instantiate a COM object by using T-SQL?  1
what is trigger NIIT1
one table has four field id,name,design,salary. i have to find maximum salary .  6
What does the INSTEAD OF trigger do?  3
What are user defined datatypes and when you should go for them?  1
what is maximum size of temp db? iSoft4
What is de-normalization and when do you do it?  3
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com