select bit mysql

mysql, tipe field adalah bit, bagaimana select datanya ?

Bismillah

q> googling ketemu SO (stackoverflow)

q> Ini DDL nya (script pembuatan table)

CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(50) DEFAULT NULL,
`enabled` bit(1) NOT NULL,
`password` varchar(60) NOT NULL,
`username` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_r43af9ap4edm43mmtq01oddj6` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1

q> Untuk datanya misalnya seperti ini (DML)

INSERT INTO users (id,email,enabled,password,username) VALUES (2,'iyar@gmail.com',true,'$2a$10$EoEKtj100Wk9DLorweEHTu9lC9d9KeCZmjfwbEzGauqkUspzON0Su','iyar');
INSERT INTO users (id,email,enabled,password,username) VALUES (3,'saifi.tesaja@gmail.com',true,'$2a$10$UL3KrXEvD0srlqf6sHYRgO5u3pIs7hGhriZuJPsYln0fgEZKg0tMi','saifi');
INSERT INTO users (id,email,enabled,password,username) VALUES (4,'wandi@gmail.com',false,'$2a$10$B/Pm4tiklZ2TlzeK70bxbOD.1Dey3YuQaDrwINUahfMJO3eyk497O','wandi');
INSERT INTO users (id,email,enabled,password,username) VALUES (5,'user1@gmail.com',false,'$2a$10$xgv/nZ0AAoZOyVzoCdsNiur9rtibj1UNcaatChwERkPV9AW97P6ZG','user1');
INSERT INTO users (id,email,enabled,password,username) VALUES (6,'user2@gmail.com',true,'$2a$10$7woMlohFwe5fErlwEB1fk.QDFot70RQF6A7svt4j66AFBRaDFHWIC','user2');

q> Query untuk mem-filter data user yang enabled = 1 atau enabled adalaha true

select * from users where enabled = (1)

q> atau

select * from users where enabled = true

q> sebaliknya untuk memfilter data yang enabled = 0 atau yang false

select * from users where enabled = (0)

q> atau

select * from users where enabled = false

q> Berhasil🙂

q> Edit tambahan

select * from users where enabled = b'1'
select * from users where enabled = b'0'

sumber:
http://stackoverflow.com/questions/839596/mysql-how-to-query-a-column-whose-type-is-bit

 

Alhamdulillah

Published by

saifiahmada

Begin a big Process with a bit trying

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s