in reply to skip empty mysql table

AFAIK, there isn't a way to conditionally create a table only if the SELECT returns some rows. You just have to query the number of rows in the new table and delete it if it is empty.

That said, I'm not sure what you are gaining in your example by creating smaller tables. If you have an index on the pat column, then it is not that less efficient to just query the main table and add a 'WHERE pat = ...' clause to restrict your query to what would be in the smaller table. Also, if you create the smaller tables, you'll have to update them whenever you update, insert or delete rows from the main table.

Finally, use placeholders!

my $a_sthexpt = $dbhexpt->prepare("CREATE TABLE TableNameexpt SEL +ECT * FROM final_exp WHERE pat = ?"); $a_sthexpt->execute($row[0]);