The Gateway to Computer Science Excellence
+2 votes

Here query is not correct if there are two persons with higher rating?Am I correct?

in Databases by Active (1.8k points) | 95 views
I think query 1 is correct while query 2 is incorrect?
If rating are distinct correct but when rating are same ?? For Example highest rating is 4 and if two persons have rating 4 then will it work??
yes it will work, take all the ratings of all the sailors of   age < 21. if the rating of a person is greater than all the ratings of the selected sailors in the  nested subquery, subquery will return NULL and then person will be selected.
S.Name rating Age

Nag        4        20

Sree      4         18

Suma     4        16

What will be the output for this table using query 1??

Sorry I didn't get clearly.So trying to understand.

regarding this table, no sailor's age os 21, hence subquery returns empty for all records, hence all be selected in the final output.note that NOT EXISTS returns True if the subquery returns empty result.

Age is less than 21 that condition will be true for all people they asked less than not equal to 21
Null (0 tuples)
sorry, yes age is < 21, result should contain Null as no rating is greater than all ratings, query still working correctly.
Ok got it so if there are more than one with higher rating it should return null.I thought it should return all people with higher rating and thought query is wrong.Thank you
see, ratings of people under age 21 are 45, 50, and 56 for example, there are two people whose ratings are 60, both will be selected using first query.

instead of trying a query on random data, try to understand the logic how a query is working.
query in the last table returned null because age of all people were < 21.
@manu sir

In the question, it is given "names of sailors". Shouldn't that allow the sailors to be more than 1 (equality allowed?)

Query one is correct. 

1 Answer

0 votes
what will be the output?


sid    sage srating

a5     20     5

a2     19     4

a1     18     3


I think answer should be null even a5 has rating higher than all sailors with age<21 according to querry 1. INCORRECT QUERRY 1???
by (345 points)

Related questions

0 votes
1 answer
asked Oct 29, 2017 in Databases by Niharika 1 Active (1.8k points) | 44 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,321 answers
105,157 users