ALL
ALL is an SQL keyword that allows a command to be executed for every record in a given table. It is typically used in conjunction with a SQL statement like SELECT, DELETE, or UPDATE to perform the action on all matching records. This keyword is particularly useful when it is necessary to perform mass operations in a database.
Example
Output
Explanation
In the above example, the SQL statement is selecting all Employee_Name
from the Employees
table where the Salary
is greater than all the salaries of employees present in Department_ID
2. As a result, we get the names of the employees who are earning more than every employee from Department_ID
2, which in this case, are John and Jane.
Example
Output
Explanation
The ALL
operator returns true if all the comparisons are true when used with a subquery. In this example, the subquery selects all salaries from the test table which are less than 50000, and then checks if the salary in the test
table where the id is 5 is greater than all the salaries returned from the subquery. The output ‘t’ in PostgreSQL is equivalent to ‘true’.
Example
Output
Explanation
The SQL query selects all employees whose salary is higher than all employees in Department 3. The result set consists of the IDs of these employees.
Example
Output
Explanation
In the given SQL query, the “ALL” operator is used with a subquery in the WHERE clause. The subquery returns the salaries of all employees in the department with id 30. The outer query then compares the salary of each employee in the ‘employees’ table with the set of salaries retrieved by the subquery. If an employee’s salary is greater than all of the salaries fetched by the subquery, their details are included in the result set. In this example, the result set consists of employees from departments other than 30, who earn more than every employee in department 30.
Example
Output
Explanation
The given SQL code first creates a table named ‘Employee’ with columns ‘ID’, ‘Name’, and ‘Salary’. It then inserts three rows into this table. The SELECT statement then retrieves all salaries from the Employee that are greater than or equal to all the salaries of the Employees who are not named ‘John’. In this case, only John’s salary of 50000 is returned because it is the smallest salary.