Order by the biggest of 2 fields

This is a discussion on Order by the biggest of 2 fields within the MySQL Database forums, part of the Database Forums category; I've a query where I've 2 dates fields in the result. I'd like to order the query ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-06-2007
Bob Bedford
 
Posts: n/a
Default Order by the biggest of 2 fields

I've a query where I've 2 dates fields in the result.

I'd like to order the query result using the biggest value from those fields
on every record.

something like order by (may(dateA,dateB)) desc.

So it orders by the biggest date of every record, no importance if the
biggest is the DateA or DateB.

How to do so ? It is possible ?

Thanks for helping.

Bob


Reply With Quote
  #2 (permalink)  
Old 09-06-2007
Captain Paralytic
 
Posts: n/a
Default Re: Order by the biggest of 2 fields

On 6 Sep, 13:29, "Bob Bedford" <b...@bedford.com> wrote:
> I've a query where I've 2 dates fields in the result.
>
> I'd like to order the query result using the biggest value from those fields
> on every record.
>
> something like order by (may(dateA,dateB)) desc.
>
> So it orders by the biggest date of every record, no importance if the
> biggest is the DateA or DateB.
>
> How to do so ? It is possible ?
>
> Thanks for helping.
>
> Bob


well you could do it like:
SELECT
IF(datea > dateb, datea, dateb) obd,
other_field
FROM table
ORDER BY 1

Reply With Quote
  #3 (permalink)  
Old 09-06-2007
Bob Bedford
 
Posts: n/a
Default Re: Order by the biggest of 2 fields

"Captain Paralytic" <paul_lautman@yahoo.com> a écrit dans le message de
news: 1189083250.835700.76250@o80g2000hse.googlegroups.c om...
> On 6 Sep, 13:29, "Bob Bedford" <b...@bedford.com> wrote:
>> I've a query where I've 2 dates fields in the result.
>>
>> I'd like to order the query result using the biggest value from those
>> fields
>> on every record.
>>
>> something like order by (may(dateA,dateB)) desc.
>>
>> So it orders by the biggest date of every record, no importance if the
>> biggest is the DateA or DateB.
>>
>> How to do so ? It is possible ?
>>
>> Thanks for helping.
>>
>> Bob

>
> well you could do it like:
> SELECT
> IF(datea > dateb, datea, dateb) obd,
> other_field
> FROM table
> ORDER BY 1


It was that simple....thanks for your help Captain.


Reply With Quote
  #4 (permalink)  
Old 09-06-2007
Captain Paralytic
 
Posts: n/a
Default Re: Order by the biggest of 2 fields

On 6 Sep, 15:15, "Bob Bedford" <b...@bedford.com> wrote:
| It was that simple....thanks for your help Captain.

I tend to find most things simple, when I know the answer!

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:54 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0