two tables are there.1st table EMP has two columns ID and name and contains data 1,A
2,B
3,C
2nd table EmpSal has 2 columns ID and Salary
Contains data -1,1000
2,5000
3,3000
Find name of employee having maximum salary ?
Answers were Sorted based on User's Feedback
Answer / gajula.lavanya
SELECT T1.NAME,T2.SAL FROM emp1 T1,emp2 T2
WHERE T1.ID=T2.ID AND T2.SAL=(SELECT MAX(SAL) FROM emp2);
| Is This Answer Correct ? | 1 Yes | 0 No |
SELECT name,min(sal) from emp1 inner join empsal where emp1.id=empsal.id
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / kanagavel
with cte
as
(
SELECT name,max(sal) as 'sal'
from emp1 inner join empsal
where emp1.id=empsal.id
group by name
)
select top 1 *
from cte
order by sal desc
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / b.kumar
--BY USING MS SQL SERVER
SELECT TOP 1 * FROM
(SELECT DISTINCT TOP 1 #A.ID,#A.NAME,#B.SAL
FROM #A INNER JOIN #B ON #A.ID=#B.ID ORDER BY SAL) E
ORDER BY SAL
--HERE #A, #B ARE TEMP TABLES
--E IS ALIAS NAME
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ganesh
with cte as
(
select *,row_number() over(order by salary desc) as rowno
from empsal
)
select * from emp e join cte c
on e.id=c.id
where c.rowno=1
| Is This Answer Correct ? | 2 Yes | 3 No |
Tell me about Triggers?
How to receive output values from stored procedures?
Can you pass expressions to stored procedure parameters?
How to execute a sql statement using mssql_query()?
Does table partitioning improve performance?
A successfully created SSIS package in SQL Server 2005 runs fine in MS BIDS and Integration Services. But gives error when run through an SQL-Job. What are the possible reasons?
Why would you call update statistics?
What purpose does the model database server?
What is the difference between a clustered index and a non-clustered index?
How to assign null values to variables or columns?
Does any body please help me what question's have asked for SSRS in the interview?
how to know description of a table in sqlserver 2000
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)