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 Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

can you instantiate a com object by using t-sql? : Sql server database administration

518


Explain what is the difference between a local and a global temporary table?

513


What is the simplest way to create a new database in ms sql server?

535


What is implicit cursors?

552


What do you understand by physical_only option in dbcc checkdb?

579






How to create a simple user defined function in ms sql server?

543


Mention the differences between local and global temporary tables.

564


Do you know how to send email from database?

552


How do I run a trace in sql server?

501


How to connect to SQL Azure Database by using sqlcmd?

110


How to get a list of columns in a view using the "sp_columns" stored procedure?

612


What do you understand by the analysis services in sql server?

536


How to create a view using data from another view?

565


What have included columns when we talk about sql server indexing?

575


role of sql sever 2005 in database rather than any other database

1510