560 views
1 1 vote

Which of the following query will give name of the employee who is earning maximum salary?

  • 1. 

    Select name from emp where sal=(Select max(sal) from emp);

    img

  • 2. 

    Select name from emp where sal>=all(Select max(sal) from emp);

    img

  • 3. 

    Both a and b are correct queries

    img

  • 4. 

    Both a and b are incorrect queries

1 Answer

Best answer
4 4 votes

Both are correct queries..

As far as the first query is concerned , first max(sal) will be computed and accordingly the corresponding employee names..

Second query also does the same thing..As there is one tuple resulting from inner query as we are finding max salary, so ALL will give same result provided we use >= or = signs..

In fact , this query will also work :

Select name from emp where sal >= all(Select sal from emp);

img

Hence  3) is the correct answer..

• selected by
Position:
Show:

Related questions

1 1 vote
1 1 answer
132
132 views
GO Classes asked Oct 2
132 views
The database contains relations $\mathrm{animals}$ and $\mathrm{visits}$, with $\mathrm{aid}$ identifying an animal.Which SQL query returns the names of animals that visi...
1 1 vote
1 1 answer
122
122 views
GO Classes asked Oct 2
122 views
The $\mathrm{Employee}$ relation contains:$$\begin{array}{|c|c|c|c|} \hline \mathrm{EmployeeNo} & \mathrm{Name} & \mathrm{DateOfBirth} & \mathrm{Department} \\ \hline 000...
3 3 votes
1 1 answer
253
253 views
GO Classes asked Oct 1
253 views
Relation $\mathrm{R}(\mathrm{at1},\mathrm{at2},\mathrm{at3})$ contains: $$\begin{array}{|c|c|c|} \hline \mathrm{at1} & \mathrm{at2} & \mathrm{at3} \\ \hline 12 & 15 & 510...
0 0 votes
1 1 answer
140
140 views
GO Classes asked Oct 1
140 views
A concert-ticket system contains $\mathrm{Sales}$ and $\mathrm{Payment}$.Relevant rules are:a row is placed in $\mathrm{Sales}$ when a purchase application is made; if pa...