Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

NOT Operator



The NOT Operator


In SQL, the NOT operator is a logical operator used to negate the result of a condition. It is commonly used in conjunction with other SQL operators such as =, <>, LIKE, IN, BETWEEN, etc., to reverse the logical outcome of a condition.

Here's a general syntax of using the NOT operator:


SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;


In this syntax:

Example:

Let's say we have a table named employees with columns employee_id, first_name, and last_name, and we want to retrieve all employees whose first name is not 'John':


SELECT employee_id, first_name, last_name
FROM employees
WHERE NOT first_name = 'John';


This query will return all rows from the employees table where the first_name column is not equal to 'John'.

You can also use the NOT operator with other operators to negate more complex conditions. For example, to retrieve all employees whose first name does not start with 'J':



SELECT employee_id, first_name, last_name
FROM employees
WHERE NOT first_name LIKE 'J%';


This query will return all rows from the employees table where the first_name column does not start with the letter 'J'.

The NOT operator is essential for building complex conditional expressions in SQL queries, allowing you to express a wide range of logical conditions


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java