Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql: How to query a column whose type is bit?

Tags:

select

mysql

bit

Hi I am using hibernate and Mysql. I have a class with a boolean attribute called 'active'.

The generated database table has the BIT data type. So far so good. I want to query this value but I don't know how to do it. I've tried

 SELECT * from table where active = 1 

doesn't work, neither the following

 SELECT * from table where active = true 

I didn't find anything neither in the reference manual nor at Stackoveflow.

Any hint?

Thanks in advance!

like image 406
Luixv Avatar asked May 08 '09 12:05

Luixv


People also ask

What is bit data type in MySQL?

The BIT data type is used to store bit values. A type of BIT( M ) enables storage of M -bit values. M can range from 1 to 64. To specify bit values, b' value ' notation can be used. value is a binary value written using zeros and ones.

Can you index a text column in MySQL?

MySQL has support for full-text indexing and searching: A full-text index in MySQL is an index of type FULLTEXT . Full-text indexes can be used only with InnoDB or MyISAM tables, and can be created only for CHAR , VARCHAR , or TEXT columns.

How do I fetch a specific column in MySQL?

If you want to select only specific columns, replace the * with the names of the columns, separated by commas. The following statement selects just the name_id, firstname and lastname fields from the master_name table.

Does MySQL have bit?

BIT is a data type used in MySQL that allows us to store bit values. The bit value comes in a range of 1-64. It will store values only in 0 and 1.


Video Answer


1 Answers

SELECT * FROM table WHERE active = (1) 
like image 102
Peter D Avatar answered Oct 10 '22 03:10

Peter D