Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find all the name using mysql query which start with the letter 'a'

Tags:

mysql

I want to find the data from table artists where name is start with letter a, b, c.

i.e.  My o/p should contain Adam Alan Bob Ben Chris Cameron  But not GlAin, doC, dolBie 
like image 819
Salil Avatar asked Dec 23 '09 08:12

Salil


People also ask

How do I find a specific letter in SQL?

SQL Server CHARINDEX() Function The CHARINDEX() function searches for a substring in a string, and returns the position. If the substring is not found, this function returns 0. Note: This function performs a case-insensitive search.

How do you select a name starting with a vowel in SQL?

To check if a name begins ends with a vowel we use the string functions to pick the first and last characters and check if they were matching with vowels using in where the condition of the query. We use the LEFT() and RIGHT() functions of the string in SQL to check the first and last characters.

How do I get the first letter of each word in SQL?

Use the INITCAP() function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase. This function takes one parameter as a string and changes the capitalization for each word as described.


2 Answers

In MySQL use the '^' to identify you want to check the first char of the string then define the array [] of letters you want to check for.

Try This

SELECT * FROM artists WHERE name REGEXP '^[abc]' 
like image 134
mike Avatar answered Sep 21 '22 20:09

mike


You can use like 'A%' expression, but if you want this query to run fast for large tables I'd recommend you to put number of first button into separate field with tiny int type.

like image 35
Dienow Avatar answered Sep 21 '22 20:09

Dienow