MySQL Forums
Forum List  »  Newbie

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

"...the last value for rssi column for all the tables order by rssi" is ambiguous. Do you mean, list the rssi value for the most recent timestamp in each table, then order that list on rssi? If so, the rssi value for the latest timestamp in table rf is ...

select rssi from rf where `date` = ( select max(`date`) from rf );

To get all such values, you would have to Union them all, and Order By that result on rssi.

Note that unless the `date` column is in the primary key, there's no guarantee that query will return just one row.

Note too the `date` column, if it's a timestamp, is incompetently named: column names should be self-documenting, ought not to mislead regarding column type.

With many such tables, writing the Union would need to be automated, and that flags another design problem: it would be more efficient to have all this in one huge table, each row carrying an identifying group number eg the numeric in your rf_* naming table-naming hack. Then your hourly query wouldn't require this folderol.



Edited 1 time(s). Last edit at 04/16/2018 01:32PM 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.