SQL AND OR & NOT Operators | Querying Data from Single Table

SQL AND OR & NOT Operators: These are basic SQL commands to use conditions-based data retrieval. In this we will see how to use this is in MySQL or any other SQL data base.

SQL AND OR & NOT Operators

1. If you are using multiple AND, OR operator then make sure you specify in braces (), because the AND operator will be executed first and then the OR.

2. NOT is used to do the opposite of any OR & AND results. See the 2nd query, we can find that we used NOT before the condition. It will check the condition and then give result opposite of that.

3. The alternate way of NOT is to change the operators wise versa. You can see in the 3rd query. [E.g., “AND” to “OR” and “<” to “<“)]. Click here to get more details!

SELECT *
FROM customers
WHERE
birth_date > '1990-01-28' OR
(points >= 1000 AND state = 'VA');
SQL AND OR & NOT Operators
SELECT *
FROM customers
WHERE NOT (birth_date > '1990-01-28' OR points > 1000);
SQL AND OR & NOT Operators
SELECT *
FROM customers
WHERE birth_date <= '1990-01-28' AND points <= 1000;
image 56

Watch Video!

Next Post>> #2.5) IN Operator (Single Table)

<< Previous Post #2.3) Where Clause (Single Table)

Vickey Rajpoot
Vickey Rajpoot

Hello there! I'm dedicated Microsoft Data & AI Engineer at LTIMindtree, where I thrive technology into actionable insights. Dive into my world by visiting my YouTube channel & Webiste, "Kingfisher Tech Tips".

Articles: 101

Leave a Reply

Your email address will not be published. Required fields are marked *