Yaseer Hussain
Yaseer Hussain

Reputation: 115

Select all tables not containing a value from database in MySql

My Database contains tables names as mentioned below and I need the tables not containing underscore(_) values:

table1
table1_xyz
table1_xyz_abc

table2
table2_xyz
table2_xyz_abc

from above example I need only talbe1 and table2 to be fetched from the query, the query used to fetch all tables names Not containing underscore(_) values in my DataBaseName:

select table_name from information_schema.tables where table_schema = 'DataBaseName' and ( table_name NOT like '%_' OR table_name NOT like '_%' OR table_name NOT like '%_%') 

but there are no results fetched.

any advice.

Upvotes: 0

Views: 293

Answers (2)

Jashil Ahammed
Jashil Ahammed

Reputation: 1

use this select table_name from information_schema.tables where table_schema = 'DataBaseName' and ( table_name NOT like '%\_' OR table_name NOT like '\_%' OR table_name NOT like '%\_%')

Upvotes: 0

Luuk
Luuk

Reputation: 14899

This can be done using a LIKE

But, some characters have special meaning like:

  • \% matches one % character.

  • \_ matches one _ character.

.

select table_name 
from information_schema.tables 
where table_name NOT like '%\_%'

Upvotes: 2

Related Questions