active が「ブール フィールド」(0 または 1 の小さな int) であると仮定します。
# Find all active users
select * from users where active
# Find all inactive users
select * from users where NOT active
つまり、「NOT」演算子をブールフィールドに直接適用できますか?
active が「ブール フィールド」(0 または 1 の小さな int) であると仮定します。
# Find all active users
select * from users where active
# Find all inactive users
select * from users where NOT active
つまり、「NOT」演算子をブールフィールドに直接適用できますか?
SQL のブール値はビット フィールドです。これは、1 または 0 のいずれかを意味します。正しい構文は次のとおりです。
select * from users where active = 1 /* All Active Users */
また
select * from users where active = 0 /* All Inactive Users */
Postgresでは、次を使用できます
select * from users where active
また
select * from users where active = 't'
整数値を使用する場合は、それを文字列と見なす必要があります。整数値は使用できません。
select * from users where active = 1 -- Does not work
select * from users where active = '1' -- Works
MS SQL 2008 では、true または false の文字列バージョンも使用できます...
select * from users where active = 'true'
-- or --
select * from users where active = 'false'
SQL Server では、一般的に使用します。他のデータベース エンジンについては知りません。
select * from users where active = 0
個人的には、boolean のネイティブ型を持たないデータベースに対して、値 'Y' と 'N' を持つ char(1) を使用することを好みます。文字は、1 が true に対応し、0 が false に対応するようになったので、それを読んだ人がそうするだろうと想定している数字よりもユーザーフレンドリーです。
(N)Hibernate を使用すると、'Y' と 'N' も適切にマップされます。