YogeshChauhan . com

SQL ALL Operator

in SQL/MySQL on October 5, 2019

SQL ALL Operator

READ ABOUT SQL ANY OPERATOR HERE.

SQL ALL operator used with WHERE or HAVING clause. It compares a value from WHERE or HAVING condition to ALL values from a subquery. It returns true if the result of subquery contains ALL selected rows. ALL must be preceded by one of the following 6 comparison operators

  1. Less than (<)
  2. Greater than (>)
  3. Less or equal to (<=)
  4. Greater or equal to (>=)
  5. Equal to (=)
  6. Not equal to <>

Let's take a look at the syntax:


SELECT column(s)
FROM table
WHERE column comparison_operator ALL
(SELECT column FROM table WHERE condition);

As you can see in the syntax above, ALL must be preceded one of the 6 comparison operators.

Let's look at the example.

NOTE: Open a DEMO link which is given at the end of the article to understand the example better.


SELECT ItemName FROM items
WHERE ItemID = ALL (SELECT ItemID FROM orderdetails WHERE Quantity > 10);

We have used 2 tables in the example. One is items and other one is orderdetails. As per the name items has items related details and orderdetails has the details of orders placed.

The SQL is going to execute the subquery inside ANY. It will check in the orderdetails that if there is an item which was ordered in more than 10 quantities in any order. If the subquery returns at ALL the rows, the results of the ANY will be set as TRUE and returns the ItemID.

In this case we will get 0 results even if we have order quantity more than 10 in some orders because it requires all the orders to be in more than 10 quantities.

dreamhost

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

How to Find the Highest (or Lowest) Number in an Array in JavaScript?JavaScriptHow to make HTML form interactive and using CSS?CSSPHP Login System using PDO Part 2: Login using Email or UsernamePHPHow to create ‘share on LinkedIn’ link using just HTML?HTMLWP_Query Class in WordPressWordPressNATURAL JOIN in PostgresPostgres