Is this the proper way to do boolean test in SQL?

Eric picture Eric · May 13, 2009 · Viewed 220k times · Source

Assume active is a "boolean field" (tiny int, with 0 or 1)

# Find all active users
select * from users where active 

# Find all inactive users
select * from users where NOT active 

In words, can the "NOT" operator be applied directly on the boolean field?

Answer

Jose Basilio picture Jose Basilio · May 13, 2009

A boolean in SQL is a bit field. This means either 1 or 0. The correct syntax is:

select * from users where active = 1 /* All Active Users */

or

select * from users where active = 0 /* All Inactive Users */