"if you encounter any errors in SAP, send me a screenshot at pramod@learntosap.com, and I will help you resolve the issue."

SQL ANY and ALL Operators

SQL TUTORIALS-

SQL ANY and ALL Operators

Introduction-


Trulli Trulli

βœ…In a Simple Word SQL, the ANY and ALL operators are used with comparison operators (like =, >, <, >=, <=, !=) to compare a value to a set of values returned by a subquery.Why this useful when comparing a single value to multiple values from another table or result set....


βœ… Syntax Example SQL ANY Operator-



expression operator ANY (subquery)



βœ… Syntax Example SQL ALL Operator-



expression operator ALL (subquery)



πŸ’‘ Note: The SQL ANY and ALL Operators Example Of Two Tables 1)-Employee. And 2)-Department
Emoji Examples in HTML

πŸ”Έ Example -)Table: Employee


EmpID Name DepID SALARY
101 ANNI 1 50000
102 RAJ 2 60000
103 POOJA 3 55000
104 SUJAN 4 70000
105 RUPESH 5 65000

Emoji Examples in HTML

πŸ”Έ Example -)Table: Department


DeptID DeptName
1 IT
2 HR
3 FINANCE

βœ… Example 1:-SQL ANY Operator-Test Find employees whose salary is greater than ANY salary in Department



SELECT * FROM EMPLOYEE
WHERE SALARY > ANY (
  SELECT SALARY FROM EMPLOYEE WHERE DEPT_ID = 1
);

βœ…Result Show :-

Result β†’

Emoji Examples in HTML

EmpID EMP_NAME SALARY
102 RAJ 60000
103 POOJA 55000
104 SUJAN 70000
104 RUPESH 65000

βœ… Example 2: SQL ALL Operator-Test Find employees whose salary is greater than ALL salaries in Department 1-



SELECT * FROM EMPLOYEE
WHERE SALARY > ALL (
  SELECT SALARY FROM EMPLOYEE WHERE DEPT_ID = 1
);

βœ…Result Show :-

Result β†’

Emoji Examples in HTML

EMP_ID EMP_NAME SALARY
104 SUJAN 70000
105 RUPESH 65000

Practice - Yes/No Quiz

1.Does SALARY > ANY (70000, 80000) return true for an employee with salary 65000?

2.Does SALARY > ANY (50000, 60000) return true for an employee with salary 55000?

3.Does SALARY > ALL (55000, 60000) return true for an employee with salary 70000?


May Be Like Important Link-

-Credit Memo and Return PO

-Bill Of Material (BOM)

-How To Create Quotation

-How To Create Debit Memo Request