1337_grl Posted May 5, 2007 Share Posted May 5, 2007 I'm using mysql5.0.32/php5.2.0-8, trying to get 2 tables echoed out together and ordered by their time columns. column_id and column_id are the primary keys for each table. The data type is the same for each of the tables and looks like: table1(column_id, time) table2(column_id, time) I've tried doing a UNION ALL between the sql statements, but have not been successful getting everything ordered by time ??? <?php include("config.php"); $sql = "(SELECT column_id, time FROM table1) UNION ALL (SELECT column_id, time FROM table2) ORDER BY time DESC"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo $row['column_id'] . ' ' . $row['time'] . '<br>'; } ?> This continues to echo all rows from each table, but does not put everything in descending order by time. If you know how this can be done, please help. Thanks Link to comment https://forums.phpfreaks.com/topic/50097-phpmysql-ordering-2-combined-tables-by-time-columns/ Share on other sites More sharing options...
neel_basu Posted May 5, 2007 Share Posted May 5, 2007 Try ORDER BY time DESC and say is it ordering or not ?? Did you tried IN query ?? Link to comment https://forums.phpfreaks.com/topic/50097-phpmysql-ordering-2-combined-tables-by-time-columns/#findComment-245980 Share on other sites More sharing options...
londonjustin Posted May 5, 2007 Share Posted May 5, 2007 Have you tried a nested table (I think that's what it's called), e.g.: "SELECT * FROM ((SELECT column_id, time FROM table1) UNION ALL (SELECT column_id, time FROM table2)) as nested_table ORDER BY nested_table.time DESC" That's just from the top of my head, so big apologies if it's not quite right.... Link to comment https://forums.phpfreaks.com/topic/50097-phpmysql-ordering-2-combined-tables-by-time-columns/#findComment-246065 Share on other sites More sharing options...
Barand Posted May 5, 2007 Share Posted May 5, 2007 What is the format of the data in the time column? Link to comment https://forums.phpfreaks.com/topic/50097-phpmysql-ordering-2-combined-tables-by-time-columns/#findComment-246105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.