Home > Software engineering >  use of wild card for set of first letters notworking mysql
use of wild card for set of first letters notworking mysql

Time:09-08

This is the query I'm using but it's returning an empty table

select ename from new_schema.employee where ename like '[svg]%' ;

CodePudding user response:

It looks like you're using Microsoft SQL Server syntax for the pattern.

MySQL only supports standard wildcards for the LIKE predicate. I.e. % and _, but not square brackets.

You can use a regular expression instead of LIKE to search for a character class:

select ename from new_schema.employee where ename REGEXP '^[svg].*' ;

You should keep in mind that every vendor of SQL database does things differently, and implements their own ideas about extensions to standard SQL. You need to refer to documentation for the brand and version you are using, and don't expect features that work in one brand (Microsoft) to work the same in another brand (MySQL).

  • Related