Jump to content

Sorting by a conditional statement possible?


akolson

Recommended Posts

I've got a table with two timestamp columns per row.  I'd like to sort all rows using the lesser of the two timestamps for each row.

I'm getting an error on a statement that tries to use ORDER BY with an IF(x>y,y,x) statement.  Is there some other way to do this?

Here's the actual situation and the script I've tried if it helps...

Situation: Each row is an entry pulled from several RSS feeds and if someone is future dating their posts I want to substitute in the 'added' timestamp instead of the 'published' timestamp whenever the published date is greater than the added timestamp.

[code]SELECT e.cid, e.id, e.url, e.title, SUBSTRING( e.description, 1, 250 ), IFNULL(e.pubdate, e.added), f.siteurl, f.title,

IF (
length( e.description ) =0, '', concat( substring( e.description, 1, 75 ) , '...' )
)
FROM feeds_item e INNER JOIN feeds_channels f ON (e.cid = f.id)

ORDER BY IF(e.pubdate>e.added,e.added,e.pubdate) DESC

LIMIT 100">[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.