- 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
Set ENUM in MySQL for column values
While creating a table, set ENUM type for the column you want ENUM values. Let us first create a table −
mysql> create table DemoTable2019 -> ( -> StudentMarks int, -> StudentStatus ENUM('First','Second','Fail') -> ); Query OK, 0 rows affected (1.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2019 values(96,'First'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2019 values(28,'Fail'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2019 values(45,'Second'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2019;
This will produce the following output −
+--------------+---------------+ | StudentMarks | StudentStatus | +--------------+---------------+ | 96 | First | | 28 | Fail | | 45 | Second | +--------------+---------------+ 3 rows in set (0.00 sec)
Following is the query to fetch records from a table with ENUM column value −
mysql> select *from DemoTable2019 -> where StudentMarks=28 -> order by StudentStatus limit 1;
This will produce the following output −
+--------------+---------------+ | StudentMarks | StudentStatus | +--------------+---------------+ | 28 | Fail | +--------------+---------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL ENUM column match for quoted values
- Set custom messages for enum values in MySQL
- Set a specific value for the first three column values in MySQL?
- Set conditions while adding column values in MySQL?
- How Are MySQL ENUM values sorted?
- MySQL query to set current date in the datetime field for all the column values
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- Set multiple values for custom columns in MySQL?
- How to set all values in a single column MySQL Query?
- Using MySQL IN() for some column values with underscore
- MySQL update column to NULL for blank values
- MySQL query to set values for NULL occurrence
- Select records with ACTIVE status in MySQL set with ENUM
- Adding new enum column to an existing MySQL table?
- Should I use MySQL enum or tinyint for fields having values 1 and 0?

Advertisements