Home > Net >  Sql query to show name not starting with vowels
Sql query to show name not starting with vowels

Time:01-25

create table test(
id int,
name char(10)
);
insert into test values(1,'sukesh');
insert into test values(2,'ramesh');
insert into test values(3,'adkjdf');
insert into test values(4,'eeuf');
insert into test values(5,'hdkjdf');
insert into test values(6,'nhkjdf');
insert into test values(7,'pdkjdf');
insert into test values(8,'adkjdf');
insert into test values(9,'oeruw');
insert into test values(10,'iblesjf');

SELECT * FROM test
WHERE name  LIKE '[!aeiou]%';

Here is what i tried but it out put is showing as Program did not output anything!

CodePudding user response:

create table test( id int, name char(10) ); insert into test values(1,'sukesh'),(2,'ramesh'),(3,'adkjdf'), (4,'eeuf'),(5,'hdkjdf'),(6,'nhkjdf'),(7,'pdkjdf')

SELECT * FROM test WHERE name NOT LIKE '[!aeiou]%'; -- Put 'NOT' CLAUSE BEFORE 'LIKE'

CodePudding user response:

You can use REGEXP for this task:

SELECT * 
FROM test
WHERE name NOT REGEXP '^[aeiou].*';

Check the demo here.

CodePudding user response:

You can use the NOT condition with RLIKE

SELECT * FROM test
WHERE name NOT RLIKE '^[aeiouAEIOU].*$'
  • Related