MySQL Forums
Forum List  »  Newbie

Re: SELECT FROM ALL TABLES / dinamic query with concat and prepare.
Posted by: Peter Brawley
Date: April 16, 2018 04:22PM

> set @sql = (concat('select * from ', table_name) as query from information_schema.tables where table_schema = 'ftth_cpe_history');

Yes, that's a remarkable syntactic mess.

When we find we've written multiple solecisms in one sql sentence, it's usually best to go back to first principles ...

(i) write all details of the query requirement in plain English---so plain, a 12-year-old with no knowledge of sql can understand it.

(ii) in turn, translate each part of that requirement into sql, testing sql bit in turn

(iii) assemble the query from those parts, test and debug

The problems arising in this thread appear to reflect a project that's been developed with too much hurry and with not enough careful design. Trite though it be, "more hurry less speed" applies very much to databases. Some of your questions here arise from not reading thoroughly enough. Your query problem arises mostly from a design that needed more thought. Slow down. One verified step at a time will save you more time, even in the short run, especially in the long run.



Edited 1 time(s). Last edit at 04/16/2018 04:24PM by Peter Brawley.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.