• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13633
  • Last Modified:

Select * FROM all tables? MySQL

I've got a database I'm working with where there's an ever expanding number of tables - associated by a specific row (let's call it "blah").

Instead of doing joins - is there syntax for me to basically say...

"SELECT * FROM all tables
WHERE blah = 'whatever'

2 Solutions
Mike EghtebasDatabase and Application DeveloperCommented:
assuming blah is a column name and string, use:

SELECT blah FROM Table1
WHERE blah = 'whatever'

will work.

If there another table with field blah, then use:

SELECT blah FROM Table1 Union
SELECT blah FROM Table2
WHERE blah = 'whatever'

and so on.

There is a way to query system tables to get the names and the [blah]s exist in the database and then design a proc to search for the information you need.

Bitaseme MboeDeveloperCommented:
This was done in SQL Server but...
SELECT * FROM sys.tables ...

Open in new window

should do the trick for you. You may have to modify the syntax to fit MY SQL.
Ray PaseurCommented:
I believe you can do something like this.  It would be easy to test.  You may have to provide aliases for the column names to eliminate ambiguity.  This is not a query you would want to run in a production environment!

SELECT * FROM table1, table2, table3...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now