I want to search for specific values in all tables from a MariaDB database and get the table name

Viewed 24

I have a database with spectral numerical data, so tables have 3 clumns and 2048 lines each, I want to search for a threshold value in one of the columns in all tables (about 30k) and get the name of that table. this will help me to analyse data faster, this is no production server and mysqldump is not an option and phpmyadmin is not working.

I really don't know where to start here but if I can get some help or hint I can probably get the rest working, I'm more a physicist than developer but can work with sql and python.

Thanks to everyone.

I read a lot of posts and really don't know how to get started with this

1 Answers

You basically have to iterate through the list of tables in the database and construct a bunch of dynamic queries that runs in a loop. Inside the loop, you look for the number you are searching for and then break out of the loop when it is found.

Here's the pseudocode:

tables = RunDBCommand("SHOW TABLES;)
foreach table in tables:
    query = "SELECT num1 FROM table WHERE col1 = '" & searchedNumber & "'"
    data = RunDBCommand(query)
    foreach row in data:
       if (row[0] == xyz)
           #found
Related