Written by Sai Sandeep Thota on March 12, 2013 in Programming > SQL

Display Records if nth Character is A or some other letter

GET ALERTS:

Get our Latest updates delivered to your mailbox!

In this we will discuss about Displaying Records if nth character is A or some other letter. For example if we want to display username records which have an alphabet “a” as second character in it.

Basically if we want to display username which start with alphabet A, then we will use:

sql > SELECT * FROM mytable WHERE username LIKE 'A%';

In the same way if we want to display usernames which have alphabet A as the second character then we will use the escape character _ (underscore).

sql > SELECT * FROM mytable WHERE username LIKE '_A%';

The above query will return Usernames which have A as second character in them.

get_nth_character

In the same way if we want to display usernames which have alphabet B as third character then:

sql > SELECT * FROM mytable WHERE username LIKE '__A%';

So the basic syntax will be like:

sql > SELECT * FROM tblname WHERE column LIKE '_a%';

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: