MySQL Forums
Forum List  »  Merge Storage Engine

Problems with UNION and ORDER BY
Posted by: steve ralph
Date: January 22, 2008 05:48PM

Hi I am trying to merge 2 database tables If I leave out the ORDER BY clause I get results from the first table. If anyone can help with the correct syntax it would be much appreciated. The code is as follows.

$query = "(SELECT CONCAT(a_item1) AS i1, (a_item2) AS i2, (a_item3) AS i3, DATE_FORMAT(db1.tbl1.tbl_date, '%M %d, %Y') AS tm FROM db1.tbl1, db1.tbl2 WHERE status = '6' AND tbl1_ID = tbl2_ID ORDER BY db1.tbl1.tbl_date DESC LIMIT 12)
UNION ALL
SELECT CONCAT(b_item1) AS i1, (b_item2) AS i2, (b_item3) AS i3, DATE_FORMAT(db2.tbl1.tbl_date, '%M %d, %Y') AS tm FROM db2.tbl1, db2.tbl2 WHERE status = '6' AND tbl1_ID = tbl2_ID ORDER BY db2.tbl1.tbl_date DESC LIMIT 12) LIMIT 6";

$result = mysql_query ($query); // Run the query

if ($result){

If I place

ORDER BY tbl_date DESC

before the last "LIMIT 6"
I do not get any results out.

Lots of thanks
Steve

Options: ReplyQuote


Subject
Views
Written By
Posted
Problems with UNION and ORDER BY
20740
January 22, 2008 05:48PM
9390
January 23, 2008 05:38PM
7927
January 23, 2008 06:43PM


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.