Inequality Operator in SQL - GeeksforGeeks

09 Jul, 2021

In this article, we will discuss the overview of operators in SQL and mainly our focus will be on Inequality Operator in SQL. Let’s discuss it one by one.
Pre-requisite – Operators in SQL
Overview :SQL Operators are widely used to access information on the basis of conditions. In the Inequality operator, we will check the condition on a specific column. Operator in SQL is used to perform conditions and on the basis of condition, the output will come. For example, if you want to find the data from the database let’s say student name then you can use an equal operator to check the name. Inequality operator is a reserved word used in an SQL statement WHERE clause to compare the two elements.
Example –In this example, let’s suppose you want to access student names from the student table from the database. So, we will use an equal operator with WHERE clause as follows.
Select * from student where name = 'ABC';
Inequality Operator in SQL :Sometimes when we want to select data that doesn’t satisfy a condition, like all students that are not in their 2nd year. Consider the given below table for reference. In this table, students is a table name and name, year, subjects are the column’s name of the table.
Example-1 :So to select those who are not in their 2nd year. So, In this, we will use the inequality operator as follows.
SELECT * FROM students WHERE year <> 2;
Output :There will be 2 records selected. These are the results you should see with either one of the SQL statements as follows.
Like before, we start with selecting all items with *. This will give us students from all years.
Since year<>2 filters out student items with 2 in the year column, we only get a student from the fourth year. 
 
Example-2 :We can also use the inequality operator with text values, like getting all students that don’t subject in ‘Java’.
SELECT * FROM students WHERE subjects <> 'Java';
There will be 2 records selected i.e “Compiler Design”, “Php”. These are the results you should see with either one of the SQL statements. In the example, both SELECT statements would return all rows from the subjects table where the subjects are not equal to Java.
 
Use : To check if a column’s value is not equal to another, we use the inequality operator <>.
Note :

What kind of value can we use the inequality operator <> with?Ans- Any kind like text and numbers. 
When is the inequality sign useful ?Ans- When you want to get all items that don’t satisfy a criterion. 

What kind of value can we use the inequality operator <> with?Ans- Any kind like text and numbers. 
When is the inequality sign useful ?Ans- When you want to get all items that don’t satisfy a criterion. 

DBMS-SQL


SQL

Writing code in comment? 
                                    Please use ide.geeksforgeeks.org, 
                                    generate link and share the link here.
                                
How to Update Multiple Columns in Single Update Statement in SQL?
SQL | Subquery
What is Temporary Table in SQL?
How to Create a Table With Multiple Foreign Keys in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
SQL using Python
SQL Query to Convert VARCHAR to INT
SQL Query to Compare Two Dates
How to Write a SQL Query For a Specific Date Range and Date Time?
How to  Select Data Between Two Dates and Times in SQL Server?