Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve rows that begin and end with specific characters?

I have one table called STUDENT. In this table there are two columns, ID and NAME. I want to retrieve all rows from this table where name starts with 'ab' and ends with 'k'. What is the SQL query for doing this?

like image 670
jaleel Avatar asked Apr 26 '11 10:04

jaleel


People also ask

How do you SELECT names that begin and end with vowels 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 retrieve a specific row in SQL?

To select rows using selection symbols for character or graphic data, use the LIKE keyword in a WHERE clause, and the underscore and percent sign as selection symbols. You can create multiple row conditions, and use the AND, OR, or IN keywords to connect the conditions.

How do I get the first row and last row in SQL?

To get the first and last record, use UNION. LIMIT is also used to get the number of records you want.


3 Answers

I think you are looking for something like:

SELECT ID, NAME FROM STUDENT WHERE NAME LIKE 'ab%k'; 

For wildcard operations you should use a WHERE clause with the LIKE keyword that allows you to filter columns that match a given pattern using the %symbol as a wildcard.

There is a question about the List of special characters for SQL LIKE clause that has a good list of LIKE special characters

like image 61
pconcepcion Avatar answered Oct 14 '22 01:10

pconcepcion


select ID, Name from student where name like 'ab%%k' 
like image 26
Kodamasimham Avatar answered Oct 14 '22 00:10

Kodamasimham


its like if you are looking for find name start with H and end with F just write query.

select emp_name from employee_test where emp_name like 'H%F';
like image 36
Hanif Khan Avatar answered Oct 14 '22 02:10

Hanif Khan