

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- 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?
- Python Pandas - Extract the frequency object as a string from the DateTimeIndex
- How can I store the fixed length string as well as variable length string in the same MySQL table?
- How to extract the whole JSON response as a string in Rest Assured?
- How can I return the values of columns from MySQL table as a set of values?
- Treat a MySQL column field as NULL if it is blank?
- How can we search a record from MySQL table having a date as a value in it?
- Searching BETWEEN dates stored as varchar in MySQL?
- Extract a data frame column values as a vector by matching a vector in R.
- Is it Possible to store and retrieve boolean values in a VARCHAR2 column in a table using JDBC?
- When MySQL SUBSTRING_INDEX() function returns the same string, provided in the argument, as output?
- How to write a MySQL stored function that updates the values in a table?
Advertisements