11.05.2010

"show tables not like" in mysql

I was looking for the tables in my database not starting with "p_".  MySQL doesn't let you execute this command:

show tables not like "p_%";

Which is odd considering it will allow "like" here:

show tables like "p_%";

Instead, you have to use the information schema like this:

SELECT table_name FROM information_schema.tables WHERE table_schema = 'mydb' AND table_name NOT LIKE 'p_%';

4 comments:

Manish Mittal said...

you can also use :

SHOW TABLES where tables_in_mydb not like 'p_%'

here 'mydb' is the name of your db.

:-)

Stetolo said...

Great post ;) !

ledkof said...

thanks Manish!!, now, it works!!!

terrellcorp said...

Thanks guys it helped alot

Post a Comment