- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Extract gender values as a string when it is stored in the table as a Boolean in MySQL
Let us first create a table −
mysql> create table DemoTable815(Gender BOOLEAN); Query OK, 0 rows affected (0.84 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable815;
This will produce the following output −
+--------+ | Gender | +--------+ | 1 | | 0 | | 0 | | 1 | +--------+ 4 rows in set (0.00 sec)
Following is the query to extract gender as a string when it is stored in the table as a boolean −
mysql> select if(Gender=true,'MALE','FEMALE') AS String from DemoTable815;
This will produce the following output −
+--------+ | String | +--------+ | MALE | | FEMALE | | FEMALE | | MALE | +--------+ 4 rows in set (0.00 sec)
- Related Articles
- Split a string and insert it as individual values into a MySQL table?
- Evaluate a boolean expression represented as string in C++
- Underscore as a table name in MySQL is possible?
- How can we find the index position of a string stored as a record in MySQL table’s column?
- How to apply EXTRACT() function on the dates stored in MySQL table?
- How to write a MySQL stored function that updates the values in a table?
- How can I store the fixed length string as well as variable length string in the same MySQL table?
- Is it Possible to store and retrieve boolean values in a VARCHAR2 column in a table using JDBC?
- How to extract the whole JSON response as a string in Rest Assured?
- How to repeat the values stored in a data column of MySQL table?
- How to write a MySQL stored function that inserts values in a table?
- How can I return the values of columns from MySQL table as a set of values?
- Python Pandas - Extract the frequency object as a string from the DateTimeIndex
- Extract a data frame column values as a vector by matching a vector in R.
- Searching BETWEEN dates stored as varchar in MySQL?

Advertisements