Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: (OT) MySQL Help
by Joost (Canon) on Jun 12, 2006 at 22:17 UTC
Re: (OT) MySQL Help
by sgifford (Prior) on Jun 12, 2006 at 22:27 UTC
    Two things that might be useful: UNION queries, which let you run several queries at once and get the results from one database handle; and MERGE tables, which let you treat several identical tables (like the ones in your example) as one big table.
      Problem with MERGE tables is they rely on the underlying tables being identical. As I understand it only the first four columns in these tables are identical so MERGE tables will be of no use.

      Hope that helps
      UnderMine

      If ID and MARK are similar across all the tables, UNION is probably the way to go.
      SELECT ID, MARK FROM Table 1 UNION SELECT ID, MARK FROM Table 2 ...
      tobin
Re: (OT) MySQL Help
by hesco (Deacon) on Jun 13, 2006 at 04:52 UTC
    While you are right, this seems like a crazy way to organize a schema, given that he's working in mysql without benefit of views and the control over access they can provide, it might actually make sense to organize this data this way.

    It may be long, it may be boring, but its essential reading if you want to use perl to manipulate a database, try perldoc DBI. You'll need it if you are going to get that valid database handle ($dbh) necessary to use the sample code above.

    -- Hugh

    if( $lal && $lol ) { $life++; }
Re: (OT) MySQL Help
by UnderMine (Friar) on Jun 13, 2006 at 05:48 UTC
    Because MySQL does not support dynamic SQL you have to write perl to wrap the required SQL. The INFORMATION_SCHEMA TABLES Table contains the info you need to generate the SQL.

    The initial SQL would look like this :-

    SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'db_name'
    Or you could use table_info on your database handle if you don't need to limit the returned list of tables or are going to filter it in perl.

    The second dynamic SQL statement would look like :-

    $sql = join ' UNION ', map "SELECT ID, Name, Class, Mark, $_ table_na +me from $_", @tables;
    Hope it help
    UnderMine