Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: What is the right syntax for NOT LIKE?

Tags:

syntax

mysql

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.

like image 512
Arman Avatar asked Sep 13 '10 08:09

Arman


1 Answers

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:

  • 12.4.5.39. SHOW TABLES Syntax.
  • 20.28. Extensions to SHOW Statements.
like image 75
kennytm Avatar answered Sep 25 '22 16:09

kennytm