1
SELECT 
  (SELECT date FROM forums WHERE topic_id=f.id OR id=f.id ORDER BY id DESC LIMIT 1) as last_reply, 
  f.*, p.id as pid, p.name FROM forums f 
      INNER JOIN players p ON p.id = f.author 
  WHERE f.topic_id=0 ORDER BY f.id DESC

In the subquery, I'd like to return not only the date field, but also the author field as well. how can I do this?

looked at a similar post but can't apply it to mine.

3
  • Did you try adding author to the list of things you select, like this: (SELECT date, author FROM forums WHERE...) Commented Apr 8, 2012 at 22:31
  • yes but the subquery is designed to search for the last posters id, not the topic poster id Commented Apr 8, 2012 at 22:39
  • 2
    I'd recommend you provide some info about the tables, because that query just doesn't seem right. Commented Apr 8, 2012 at 22:41

2 Answers 2

2

I would do it something like this:

SELECT 
  (SELECT date FROM forums WHERE topic_id=f.id OR id=f.id ORDER BY id DESC LIMIT 1) as last_reply,
  (SELECT author FROM forums WHERE topic_id=f.id OR id=f.id ORDER BY id DESC LIMIT 1) as last_author,
  f.*, p.id as pid, p.name FROM forums f 
      INNER JOIN players p ON p.id = f.author 
  WHERE f.topic_id=0 ORDER BY f.id DESC

I would actually repeat the subquery again

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

Comments

0

Maybe something like this can help you :

SELECT MAX(f.date), f.author
FROM forums f
    INNER JOIN players p ON
        p.id = f.author
WHERE f.tpoic_id = 0
GROUP BY f.author
ORDER BY f.id DESC

But it's difficult with no structure of tables.

Good luck.

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.