Lahari Gulimi
Lahari Gulimi

Reputation: 11

Wildcards in SQL doesn't return the expected output

I tried to run a SQL script in MySQL DB as below

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'ACT_%' OR TABLE_NAME LIKE 'IMS_PPH%';

In the response it is showing 'actor' and 'actor_info' table names even though I filtered with 'ACT_%'.

Upvotes: 1

Views: 46

Answers (1)

kmoser
kmoser

Reputation: 9273

In MySQL, the underscore character ('_') is a wildcard that matches any character, which is why "ACT_" matches tables beginning with "ACT" followed by any character, which includes your "ACTOR" table.

If you want to treat "_" as a literal underscore, you must escape it, e.g. "ACT\_%".

Upvotes: 2

Related Questions