
- 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
Find all the names beginning with the letter 'a' or βbβ or βcβ using MySQL query?
You need to use LIKE with OR operator to find all the names that starts with a or b or c. The syntax is as follows:
SELECT *FROM yourTableName WHERE yourColumnName like 'A%' or yourColumnName like 'B%' or yourColumnName like 'C%';
The above query finds all names that starts only with the letter ‘a’ or ‘b’ or ‘c’. To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table AllNamesStartWithAorBorC -> ( -> Id int NOT NULL AUTO_INCREMENT, -> EmployeeName varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.70 sec)
Insert some records in the table using insert command. The query is as follows:
mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Adam'); Query OK, 1 row affected (0.19 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Bob'); Query OK, 1 row affected (0.16 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('baden'); Query OK, 1 row affected (0.48 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Carol'); Query OK, 1 row affected (0.41 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Larry'); Query OK, 1 row affected (0.16 sec) mysql> insert into AllNamesStartWithAorBorC(EmployeeName) values('Chris'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement. The query is as follows:
mysql> select *from AllNamesStartWithAorBorC;
The following is the output:
+----+--------------+ | Id | EmployeeName | +----+--------------+ | 1 | Adam | | 2 | Bob | | 3 | baden | | 4 | Carol | | 5 | Mike | | 6 | Larry | | 7 | Chris | +----+--------------+ 7 rows in set (0.00 sec)
Here is the query to find names that begins with a or b or c. The query is as follows:
mysql> select *from AllNamesStartWithAorBorC where EmployeeName like 'A%' or EmployeeName like 'B%' or -> EmployeeName like 'C%';
The following is the output:
+----+--------------+ | Id | EmployeeName | +----+--------------+ | 1 | Adam | | 2 | Bob | | 3 | baden | | 4 | Carol | | 7 | Chris | +----+--------------+ 5 rows in set (0.00 sec)
- Related Articles
- MySQL query to select all fields beginning with a given number with next character a letter?
- Get the names beginning with a particular character using LIKE in MySQL
- Select particular type of columns beginning with a certain letter and concatenate the names
- MySQL Order by beginning letter?
- MySQL query to display all the fields that contain a capital letter?
- Make all column names lower case in MySQL with a single query
- MySQL query with OR & AND conditions
- Query MongoDB with βlikeβ implementation on name and email field beginning with a specific letter?
- Fetch a specific record using a single MySQL query with AND & OR operator
- MySQL query to perform selection using AND OR
- Set 'alias' for all the column names in a single MySQL query
- How do you fill in or pad a column with zeros using a MySQL query?
- The MySQL EXPLAIN keyword executes the query or just explains the query?
- Working with MySQL WHERE.. OR query with multiple OR usage. Is there an alternative?
- The scientist who proposed the first letter (or first letter and another letter) of the Latin or English name of an element as its symbol, was :(a) Dalton (b) Proust (c) Lavoisier (d) Berzelius

Advertisements