Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?

Answers were Sorted based on User's Feedback



how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / newbie

SELECT MAX(E.Salary) FROM
(SELECT MAX(Salary) SalaryFROM dep1
UNION
SELECT MAX(Salary) Salary FROM dep2) E

Is This Answer Correct ?    36 Yes 5 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / sumathy

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 ?    13 Yes 2 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / swati tripathi

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 ?    8 Yes 4 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / veeresh kethari

User CTE:

with Temp as(select max(sal) Sal from Table1
union
select max(sal) sal from Table2)
select top 1 * from Temp order by sal desc

Is This Answer Correct ?    3 Yes 0 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / saurabh agrawal

select top 1 empid, empname, max(salary) from (
Select empid, empname, salary = max(salary) from dep1 group
by empid, empname
union all
Select empid, empname, salary = max(salary) from dep2 group
by empid, empname
)A
group by empid, empname order by max(salary) desc

Is This Answer Correct ?    1 Yes 0 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / praveend

Try this. I have tried it.

Select id, name, Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as B


where salary = (
Select Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as C
)

Is This Answer Correct ?    1 Yes 0 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / kaka

create table #temp
(salary numeric(18,0)
)
insert into #temp
select max(salary) as salary from EmpSalary
union
select max(salary)as salary from EmpSalary1
select max(salary) from #temp
drop table #temp

Is This Answer Correct ?    1 Yes 1 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / lince p. thomas

select T.empname,salary from
(
select a.empname as empname ,a.salary as salary from dep1 a
union all
select b.empname as empname,b.salary as salary from dept2 b
)T where T.salary=(select max(T.salary) as salary from
(select max(a.salary) as salary,a.empname as empname
from dep1 a group by a.empname
union all
select max(b.salary)as salary,b.empname as empname from
dept2 b group by b.empname)T
)

Is This Answer Correct ?    0 Yes 0 No

how to get the maximum among two tables,for example table 1 (dep1) have (emp_id,emp_name,salary) c..

Answer / akhilesh

Try this. I have tried it.

Select id, name, Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as B


where salary = (
Select Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as C
)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is outer join in sql server joins?

0 Answers  


What is the guest user account in sql server? What login is it mapped to it? : sql server security

0 Answers  


How to call a function from a stored procedure in SQL Server ?

0 Answers   HCL,


Define magic tables in sql server?

0 Answers  


can you anybody tell me the how can you restore the master database. while migraion(one server to onther server)?

1 Answers  


Explain relational data?

0 Answers  


What is query and its types?

0 Answers  


Is it safe to delete log files?

0 Answers  


What is a collation in ms sql server?

0 Answers  


How to check if stored procedure is running in sql server?

0 Answers  


sql server syntax to add "!" sign to "name" field of "employee" table in a manner that all names have the same lenght of 20 characters

1 Answers  


how to generate XML out of QUERY?

1 Answers   McAfee,


Categories