Some Common Mistakes In SQL (Part 1)

Posted by

This blog I want to write about a common mistake I once make in SQL, which about NULL and WHERE CLAUSE.

WHERE CLAUSE:

SELECT Column1, Column2,..., ColumnN
FROM SchemaName.TableName
WHERE ColumnName {Comparison operator}[Filtering Criteria]

1 NULL

Example: Find all rows in Person.Person, which MiddleName is NULL.

Common mistakes:

SELECT *
FROM Person.Person
WHERE MiddleName is = NULL
SELECT *
FROM Person.Person
WHERE MiddleName is = 'NULL'

Correct code:

SELECT *
FROM Person.Person
WHERE MiddleName IS NULL

2 NOT NULL

Similarly, if we want to find all rows in Person.Person, which MiddleName is NOT NULL.

The operator means ‘not equal’ is <>,

so,

Common mistakes:

SELECT *
FROM Person.Person
WHERE MiddleName <> NULL

Correct code:

SELECT *
FROM Person.Person
WHERE MiddleName IS NOT NULL

I will record all mistakes I make in my Business Intelligence journey.

I will also learn more through my mistakes.

If you are interested in some high income skills or have any problems with Business Intelligence, feel free to contact me .

Or you can connect with me through my LinkedIn.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s