
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to select column where value = one or value = two, value = three, etc?
Let us first create a table −
mysql> create table DemoTable ( UserId int, UserName varchar(10), UserAge int ); Query OK, 0 rows affected (0.73 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(101,'Chris',23); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(102,'Robert',33); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(103,'David',25); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(104,'Carol',35); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(105,'Bob',29); Query OK, 1 row affected (0.17 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+--------+----------+---------+ | UserId | UserName | UserAge | +--------+----------+---------+ | 101 | Chris | 23 | | 102 | Robert | 33 | | 103 | David | 25 | | 104 | Carol | 35 | | 105 | Bob | 29 | +--------+----------+---------+ 5 rows in set (0.00 sec)
Following is the query to select the column where value = one or value = two, etc i.e. UserAge in our table with different ages −
mysql> select *from DemoTable where UserAge=25 or UserAge=35 or UserAge=33 or UserAge=29;
This will produce the following output −
+--------+----------+---------+ | UserId | UserName | UserAge | +--------+----------+---------+ | 102 | Robert | 33 | | 103 | David | 25 | | 104 | Carol | 35 | | 105 | Bob | 29 | +--------+----------+---------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to select rows where column value is only 0, group by another column?
- How to select distinct value from one MySQL column only?
- MySQL SELECT to sum a column value with previous value
- MySQL query to replace a column value
- Select a specific value between two column values in MySQL?
- MySQL query to delete last two words from every column value
- Show column value twice in MySQL Select?
- SELECT where row value contains string in MySQL?
- MySQL Select where value exists more than once
- MySQL select query to fetch data with null value?
- MySQL query to select the nth highest value in a column by skipping values
- MySQL Select Rows where two columns do not have the same value?
- MySQL SELECT to add a new column to a query and give it a value?
- MySQL query to replace special characters from column value
- Select from table where value does not exist with MySQL?

Advertisements