

- 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
Only display specified values inside the IN clause with MySQL?
For this, you can use IN() along with ORDER BY clause. Let us first create a table −
mysql> create table DemoTable1986 ( Number int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1986 values(50); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(200); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(350); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1986;
This will produce the following output −
+--------+ | Number | +--------+ | 50 | | 60 | | 100 | | 200 | | 350 | +--------+ 5 rows in set (0.00 sec)
Here is the query to show specified id inside the IN clause −
mysql> select * from DemoTable1986 where Number IN(50,100,350) order by field(Number,350,100,50);
This will produce the following output −
+--------+ | Number | +--------+ | 350 | | 100 | | 50 | +--------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
- MySQL query to compare and display only the rows with NULL values
- Display only the default values set for columns in MySQL
- MySQL query to display only the column values with corresponding column having whitespace
- Update with multiple values in MySQL WHERE clause
- MySQL query to display only the empty and NULL values together?
- Only display row with highest ID in MySQL
- Display MySQL histogram with negative values?
- Can we fetch multiple values with MySQL WHERE Clause?
- GROUP BY and display only non-empty column values in MySQL
- Insert row with only default values in MySQL
- Can we use WHERE clause inside MySQL CASE statement?
- Find and display duplicate values only once from a column in MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- MySQL query to retrieve only the column values with special characters?
Advertisements