
- 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
How to select a row where one of several columns equals a certain value in MySQL?
For this, you can use multiple OR. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(10), LastName varchar(10), Age int, CountryName varchar(10) ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('John','Smith',21,'US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('Carol','Taylor',22,'AUS'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName,LastName,Age,CountryName) values('David','Miller',19,'UK'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+-----------+----------+------+-------------+ | Id | FirstName | LastName | Age | CountryName | +----+-----------+----------+------+-------------+ | 1 | John | Smith | 21 | US | | 2 | Carol | Taylor | 22 | AUS | | 3 | David | Miller | 19 | UK | +----+-----------+----------+------+-------------+ 3 rows in set (0.00 sec)
Following is the query to select a row where one of several columns equals a certain value −
mysql> select *from DemoTable where FirstName="Carol" OR Age=22 OR CountryName="AUS";
Output
+----+-----------+----------+------+-------------+ | Id | FirstName | LastName | Age | CountryName | +----+-----------+----------+------+-------------+ | 2 | Carol | Taylor | 22 | AUS | +----+-----------+----------+------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- SELECT where row value contains string in MySQL?
- SELECT a row by subtracting dates in WHERE in MySQL?
- How to select all the records except a row with certain id from a MySQL table?
- How to select data in MySQL where a field has a minimum value?
- MySQL query to select column where value = one or value = two, value = three, etc?
- MySQL Select Rows where two columns do not have the same value?
- Comparing two columns in a single MySQL query to get one row?
- DELETE from MySQL table WHERE column equals value AND column2 equals value2?
- SELECT * WHERE var == [one of many alternatives] in MySQL?
- Select a random row in MySQL
- How do you select from MySQL where last value in a string = x?
- How to select most recent date out of a set of several possible timestamps in MySQL?
- How to select row when column must satisfy multiple value in MySQL?
- MySQL LIMIT to select a single row
- How to select all columns except one in a Pandas DataFrame?

Advertisements