Select From all tables - MySQL Select From all tables - MySQL sql sql

Select From all tables - MySQL


You get all tables containing the column product using this statment:

SELECT DISTINCT TABLE_NAME     FROM INFORMATION_SCHEMA.COLUMNS    WHERE COLUMN_NAME IN ('Product')        AND TABLE_SCHEMA='YourDatabase';

Then you have to run a cursor on these tables so you select eachtime:

Select * from OneTable where product like '%XYZ%'

The results should be entered into a 3rd table or view, take a look here.

Notice: This can work only if the structure of all table is similar, otherwise aou will have to see which columns are united for all these tables and create your result table / View to contain only these columns.


SELECT product FROM Your_table_name WHERE Product LIKE '%XYZ%';

The above statement will show result from a single table. If you want to add more tables then simply use the UNION statement.

SELECT product FROM Table_name_1 WHERE Product LIKE '%XYZ%'  UNION  SELECT product FROM Table_name_2 WHERE Product LIKE '%XYZ%'  UNION  SELECT product FROM Table_name_3 WHERE Product LIKE '%XYZ%' 

... and so on


As Suhel Meman said in the comments:

SELECT column1, column2, column3 FROM table 1UNIONSELECT column1, column2, column3 FROM table 2...

would work.

But all your SELECTS would have to consist of the same amount of columns. And because you are displaying it in one resulting table they should contain the same information.

What you might want to do, is a JOIN on Product ID or something like that. This way you would get more columns, which makes more sense most of the time.