1

This works...

$sql30 = "SELECT * FROM statuses LEFT JOIN friends ON statuses.userID=friends.lowerFriendID WHERE friends.lowerFriendID != :user_ida
    UNION SELECT * FROM statuses RIGHT JOIN friends ON statuses.userID=friends.higherFriendID WHERE friends.higherFriendID != :user_idb ORDER BY userID DESC";

But I don't need to sort by userID, this does not work...

$sql30 = "SELECT * FROM statuses LEFT JOIN friends ON statuses.userID=friends.lowerFriendID WHERE friends.lowerFriendID != :user_ida
    UNION SELECT * FROM statuses RIGHT JOIN friends ON statuses.userID=friends.higherFriendID WHERE friends.higherFriendID != :user_idb ORDER BY id DESC";

nor does this...

$sql30 = "SELECT * FROM statuses LEFT JOIN friends ON statuses.userID=friends.lowerFriendID WHERE friends.lowerFriendID != :user_ida
    UNION SELECT * FROM statuses RIGHT JOIN friends ON statuses.userID=friends.higherFriendID WHERE friends.higherFriendID != :user_idb ORDER BY `id` DESC";

nor does this...

$sql30 = "SELECT * FROM statuses LEFT JOIN friends ON statuses.userID=friends.lowerFriendID WHERE friends.lowerFriendID != :user_ida
    UNION SELECT * FROM statuses RIGHT JOIN friends ON statuses.userID=friends.higherFriendID WHERE friends.higherFriendID != :user_idb ORDER BY timestamp DESC";

I need to order by either "id" or "timestamp" DESC so that the most recent post shows first. Your help is much appreciated. Thank You!

Donald
  • 35
  • 1
  • 5
  • you need to define field of particular table. like ORDER BY . – Rakesh Sojitra Jan 17 '16 at 05:03
  • It's difficult to help without seeing the table structure. When you say the other queries don't work, are you getting any errors or are they just not returning the data you expect? – Jeff Kilbride Jan 17 '16 at 05:04
  • I also tried statuses.id and statuses.timestamp, also did not work. No errors, just not returning any data. The first query ORDER BY userID DESC returns expected results. Is there any reason in the table structure that could change the expected outcome such as the type (int, varchar) of the column? – Donald Jan 17 '16 at 05:07
  • CREATE TABLE IF NOT EXISTS `statuses` ( `id` int(25) NOT NULL AUTO_INCREMENT, `status` text NOT NULL, `userID` int(10) NOT NULL, `privacy` int(1) NOT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted` int(1) NOT NULL, `edited` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; – Donald Jan 17 '16 at 05:09
  • It might also help to know that it doesn't just fail the query, but it breaks the code for the rest of the page too. Nothing below this shows on the page, even unrelated content. – Donald Jan 17 '16 at 05:14

0 Answers0