Reputation: 1
How to display names who's initial are starting from K,B,A in sql? The result should comes like eg:-Keven,karun,Bean,Brown,Aron,Abiel
Upvotes: 0
Views: 309
Reputation: 8103
Use REGEXP_LIKE as shown below. It can match a regular expression, which is a better alternative in this case instead of using multiple like
statements.
select name from
your_table t
where REGEXP_LIKE (name, '^[K|B|A]','i');
Regex ^[K|B|A]
matches every word which starts with either K or B or A
. i
for case insensitive matching.
Upvotes: 0
Reputation: 1673
Select name_field
From yourTable
Where upper( substr( name_field, 1, 1)) in ('K', 'B', 'A')
Upvotes: 1
Reputation: 1815
SELECT name FROM users WHERE name LIKE 'k%' OR name LIKE 'b%' OR name LIKE 'a%' COLLATE utf8_general_ci
%
matches any string, so the above query will match any name starting with b, a or k. the COLLATE rule is there to tell the query that it is case insensitive.
Upvotes: 0
Reputation: 1675
You could use REGEX_LIKE to perform this operation.
What it does is it performs a regular expression matching instead of a simple pattern matching.
Upvotes: 0