What is NULL?
Sometimes, It’s not necessary to fill up each and every field with data/information, whenever be a record is inserted or updated. If a record is inserted only with targeted fields only (leaving other fields ), then automatically that particular field/column would get NULL value.
It can be avoided by using NOT NULL constraint that would prevent from entering NULL value.
How to know which field contain NULL value ?
IS NULL
IS NOT NULL
Check a column Contains NULL or Empty String using WHERE Clause in SQL?
SELECT * FROM customers WHERE customer_lastname IS NULL OR customer_lastname = ''
Output:
About Where Clause
In SQL, WHERE Clause is used to specify a condition and fetching the data from the given table. whether it is single table or by joining of multiple ones. If the condition is satisfied, the result comes out with specific values. So we should use the WHERE clause to filter the records and extract the results that fulfilling specific condition.
In SQL the WHERE clause not only used with the SELECT statements but also with the UPDATE, DELETE statements etc. for getting small clues, some examples/syntax are here to get through but for gaining more about it, we would examine these in next subsequent posts.
Syntax:
SELECT column1, column2, columnN
FROM table_name
WHERE condition;
For Example:
From an Extract of the table data which shows the List of Customers of different Countries and we filter out for some let’s say “India”. So, the Problems become is “List of Customers in India” and there columns contains ID, Name, Product, City, and Country. let’s find out how it filters:
1. SELECT ID, Name, Product, City, Country
2. FROM Customers
3. WHERE Country = ‘India’
Output:
There you go “Result” in before your eyes.
There are many Operators that can be used in WHERE clause as:
< > not equal
= equal
> grater than
< less than
LIKE, BETWEEN & IN are also the Operators which can be used in WHERE clause for searching a pattern, Between an inclusive range & to specify the multiple values for a column respectively.