53

There are too many tables in a db. how can I only show tables with certain patterns? Or is there a way I can do paging like "| more" in shell command?

1
  • not for mysql, but for oracle, you can do "select * from cat where table_name like '%xxxx'". the same functionality must exist for mysql
    – KevinDTimm
    Aug 4, 2010 at 16:33

5 Answers 5

94
show tables like 'pattern';
4
  • 12
    I also found show tables like '%pattern%'; works too : ) Jun 6, 2016 at 7:29
  • 6
    @michaelmcgurk, the % is the wildcard in any like statement. Therefore a'r was correct...the pattern can be anything you are searching for, including wildcards. Jan 25, 2017 at 16:28
  • 1
    What is the way if I want to SHOW TABLES LIKE 'xxx_%' but I don't want the underscore character as a wildcard... ? SHOW TABLES LIKE 'xx#_%' ESCAPE '#' don't work for me... Nov 23, 2020 at 12:13
  • If you want to use the same command on dbfs Azure Databricks, instead of the typical SQL wildcard % use *
    – Ric S
    Jan 10 at 16:59
9
  • use show tables like 'pattern'
  • pattern is a string using wildcard characters "%","_"
  • % matches any number of characters, even zero characters.
  • _ matches exactly one character.

for example:

  • show tables like 'test%' will filter tables such as "test1,testF,test111,testFoo"

  • show tables like 'test_' will filter tables such as "test1,testF"

3

You don't have to use show tables, you can also query information_schema.TABLES using any filter.

3
  • Can you give an example or link? Where is the information_schema.TABLES located?
    – Despertar
    Mar 4, 2012 at 0:01
  • Information_schema is a MySQL system DB. You can check dev.mysql.com/doc/refman/5.0/en/information-schema.html for details
    – a1ex07
    Mar 4, 2012 at 13:51
  • SELECT * from information_schema.TABLES WHERE TABLE_NAME LIKE 'oc_%';
    – t2d
    Nov 22, 2019 at 16:29
0

In Spark SQL you need to use an asterisk symbol, SHOW tables LIKE '*table_name*

-4

this can be used to have a glimpse of all the tables

select * from tab;

and identify the columns names. Thereafter, use

select * from tab where tname like '%D_';
1
  • This is incorrect. This would query a table, not show tables that would have a pattern name for a table Jun 5, 2014 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.