- 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 custom messages on the basis of a column with student marks in MySQL
For this, use CASE statement. Let us first create a table −
mysql> create table DemoTable1952 ( Marks int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1952 values(35); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(65); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(39); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1952;
This will produce the following output −
+-------+ | Marks | +-------+ | 35 | | 65 | | 55 | | 39 | +-------+ 4 rows in set (0.00 sec)
Here is the query to set custom messages on the basis of student marks:
mysql> select case when Marks > 40 then 'Good Marks' else 'Not Good Marks' end as Result from DemoTable1952;
This will produce the following output −
+----------------+ | Result | +----------------+ | Not Good Marks | | Good Marks | | Good Marks | | Not Good Marks | +----------------+ 4 rows in set (0.00 sec)
- Related Articles
- Display the student marks in a single column on the basis of subject in MySQL?
- Set custom messages for enum values in MySQL
- Display custom text in a new column on the basis of null values in MySQL?
- Set custom messages by working with MySQL IF Statements and SELECT in a user-defined variable
- Find the percentage of a student on basis of marks and add percent sign (%) to the result in SQL
- Add a new column and set values in it on the basis of conditions in MySQL?
- Write MySQL case statement to set custom messages for student’s result
- Group the marks of a particular student from a table and display total marks in a separate column for each student?
- Concatenate rows on the basis of boolean values in another column with MySQL
- Determining rank on basis of marks in JavaScript
- Match column values on the basis of the other two column values in MySQL
- How to sort MySQL output on the basis of the column which is not in the result set?
- Perform MySQL UPDATE on the basis of DATE value in another column
- Add a column count in a MySQL query on the basis of last name records?
- Fetch maximum individual marks for a student with marks1 and marks2 records in MySQL?

Advertisements