Mireille28 Mireille28 - 5 months ago 8
MySQL Question

How to make this query get some data from another table in reverse order

hi actually i have a query that work pretty fine this is my query

SELECT *
FROM ( SELECT * FROM `chat` WHERE `post_roomid` = '$room' AND post_id > '$last' AND user_id != $uid" ORDER BY `post_id` DESC LIMIT 60) AS log
ORDER BY `post_id` ASC


it actually work but i do not understand how to make a join with this query and keep the inverted order of post

i need to retreive some data from user table where user_id from user_table will fit user_id from chat table but i need to keep the result in same order

thanks for help

Answer

For inverted order you use

SELECT log.*, users.user_rank, users.user_id 
FROM ( SELECT * 
            FROM `chat` 
            WHERE `post_roomid` = '$room' 
            AND post_id > '$last' 
            AND user_id != $uid" 
            ORDER BY `post_id` DESC
             LIMIT 60) AS log 
LEFT  JOIN user log.user_id = user.user_id
ORDER BY log.`post_id` ASC
Comments