Tutorials

SQL Clause and Operator


SQL NOT


In SQL, NOT is used with WHERE clause to select all those rows where the column value does not belongs to given condition.

Syntax for NOT


SELECTFROM table_name
WHERE NOT column = 'value';

Here all the records will be ommited where column does not contain the given 'value'

 

Example on NOT

 

For demonstration we will take help of tih_Corses table:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
 

Query-1: Write sql query to select all those records where course id is not 004.


SELECTFROM tih_Courses
WHERE NOT Course_ID = 004;

On executing the above query successfully, we will get following result:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online

 



Please Share this page
Views : 25