Monday 15 August 2011

mysql - How can I do a global select over multiple tables in the database or something equivalent? -


I have a series of tables in the same database, table names are different in groups, i.e. one of the tables in the same group The prefix is ​​the same.
These tables share a column (at least one) with the same information and one column name (except for a few tables, the name of the column is different).
What am I interested, to know which tables have specific values ​​i.e. I would like to get the table names that have a specific value in their column or I would likewise want to do a SELECT * WHERE COLUMN = value on all the tables and get all the records. I would like to like table names unless it is very difficult.
What was done to get me the results:
I manually wrote a selection in an editor on the All tables, a group (i.e. the same prefix) and where the clause
I have copied / pasted all these selections and run them in the query cleaner. Then I changed everything in the editor and changed the table names to another group and then copied / pasted and run it.
I kept copying / copying / pasting for all the tables (and even if necessary, the column was named for the name).
What do I want to do to do this, but it looks stupid for me.
I think there should be a more "professional" method than this method, but I do not know how.
What would be the best way to do this? The way if I had another example 5 groups would have me do more on this.

Maybe you can be able to create things to make a little easier by considering the tables which you In the form of tab 'name' in the form of a 'tab' view group group_on_view as something like <1>, select the UNION all tab from field 1, Table 1, select the tab ' Select all tabs from Table 1 in Table 1 as 'tabc' tab_name, separated by table id diff_field_name

then you can specify group_one_view You can use it as if it is a table

  select_ from group_one_view where field 1 = 'paneer'   

Edit

You may be able to get some help from Info_schema (The query must be completed to a certain extent - but a little keyboard can save the job)

 Information from SELECT CONCAT ('Select' '', table_name, '' 'tab_name, field 1', table_name, 'union all') 'Group_prefix_%' like 'tabs' table_name    

No comments:

Post a Comment