0
'SELECT conversation_id, viewed_on,('max_unixtime().' - last_reply) AS newest_conversation FROM `Conversation_Participant` WHERE `user_id`='.$self->{user}->get('id').' ORDER BY newest_conversation DESC'

I need to set newest_conversation only when max_unixtime() - last_reply > last_viewed..

how can i set the if statement within my query?

1
  • 2
    And when max_unixtime() - last_reply **IS NOT** > last_viewed, then what should happen? Commented Jul 15, 2011 at 20:07

1 Answer 1

2

Use a CASE statement.

...CASE WHEN max_unixtime() - last_reply > last_viewed 
        THEN ('max_unixtime().' - last_reply) 
        ELSE NULL END AS newest_conversation...
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.