14

Hi I am trying to show tables with names not like a pattern by mysql is throws an error:

SHOW TABLES  NOT LIKE  "tree%";

returns:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT LIKE "tree%"' at line 1

What is the right syntax?

Thanks Arman.

Arman
  • 4,566
  • 10
  • 45
  • 66

3 Answers3

41

You could use the WHERE clause extension, as in:

SHOW TABLES WHERE `Tables_in_<DatabaseName>` NOT LIKE 'tree%';

This is supported on MySQL ≥5.0.

Reference:

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
1

LIKE and NOT LIKE are used with SELECT statements. I don't think this works with the SHOW TABLES command.

Andrew Vit
  • 18,961
  • 6
  • 77
  • 84
  • Indeed, found that out just now (MySQL 5.7.27 or thereabouts). See the answer by [@kennytm](https://stackoverflow.com/a/3698917/1035977) for the correct workaround. – Gwyneth Llewelyn Oct 02 '19 at 21:39
0

According to this feature request, this has been introduced in mySQL 5.0.3. However, people there disagree, and it doesn't work in my 5.1.41 installation, either.

I guess the answer is it's not possible.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088