Home > OS >  SQL LIKE - Any word that contains a letter once?
SQL LIKE - Any word that contains a letter once?

Time:08-31

Case (with 'a'):
    amsterdam - False, contains more than an 'a'
    alceribobo - True, has exactly 'a' once.
    fermin - False, doesn't contain any 'a'

I want to Select every word with that regular expression using SQL LIKE operator or SQL REGEXP_LIKE.

i.e.

SELECT * FROM table1 where table1.name LIKE '...';
    results:
      alceribobo

CodePudding user response:

Could it be this?

SELECT * FROM table1 where table1.name LIKE '%a%' and not table1.name LIKE '%a%a%;

Note that using LIKE may have a negative impact on performance: SQL 'like' vs '=' performance

CodePudding user response:

Try this and let me know.

SELECT * FROM EMPLOYEES WHERE REGEXP_LIKE(FIRST_NAME,'a{1}'); 
  • Related