Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

SQL | SOME

  • Difficulty Level : Easy
  • Last Updated : 21 Mar, 2018

SQL | ALL and ANY
SOME operator evaluates the condition between the outer and inner tables and evaluates to true if the final result returns any one row. If not, then it evaluates to false.

  • The SOME and ANY comparison conditions are similar to each other and are completely interchangeable.
  • SOME must match at least one row in the subquery and must be preceded by comparison operators.

Syntax:

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

SELECT column_name(s)
FROM table_name
WHERE expression comparison_operator SOME (subquery)


Instructor Table:

NameDepartmentSalary
ChandraComputational Biology1
VisweswaranElectronics1.5
AbrahamComputer Science1.3
JohnElectronics1.2
SamanthaComputer Science2
JyotiElectronics1.2
DebarkaComputer Science2
GaneshComputational Biology0.9

Sample Queries and Outputs:



select name
from instructor
where Salary > some(select Salary
from instructor
where dept='Computer Science');

Output:

Visweswaran
Samantha
Debarka

Explanation
The instructors with salary > (salary of some instructor in the ‘Computer Science’ department) get returned. The salaries in the ‘Computer Science’ department are 1.3, 2 and 2. This implies any instructor with a salary greater than 1.3 can be included in the final result.

Exercise: Try to write same query using ANY clause.

This article is contributed by Anannya Uberoi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!