0

I have this query already:

SELECT * FROM (SELECT * FROM `prefix_messages`
                        WHERE `category_id`=4
                        ORDER BY `id` DESC LIMIT 30) ilv
         ORDER BY `id` ASC

How to use join query to add data from users table if in prefix_messages I have user_id column?

Thanx!

1
  • 1
    How can you imagine an answer without any knowledge of tables schema? Commented Aug 9, 2011 at 21:54

1 Answer 1

1

Try this:

SELECT * FROM   (SELECT pm.ID as prefixID, * FROM prefix_messages as pm
    INNER JOIN users as u
    ON pm.User_id = u.UserId
    WHERE pm.category_id=4
    ORDER BY pm.id DESC LIMIT 30)
    ORDER BY prefixID ASC

I assume that you are only doing the subselect because you want to reverse the order after you get the top 30?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.