MySqlTalk.com  

Go Back   MySqlTalk.com > Programming Languages and MySQL > PHP
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 11-19-2004, 07:54 PM   #1
freeware
Junior Member
 
Join Date: Nov 2004
Posts: 3 freeware is on a distinguished road
Need results sorted by 2 fields, not 1

Hello,

I'm trying to sort a resultset by 2 fields. I have a table "program" which has dozen of fields (program specs). When a new program is inserted, a date field called Date_Submitted has the current date. When the program is updated with new information, the field named Date_Updated get the current date.

I want to be able to return a resultset that is sorted by, both, Date_Submitted and Date_Updated so that I can list on my site which programs are new and which have been updated.

I have something that sort of works:
SELECT * FROM program
ORDER BY Date_Submitted desc, Date_Updated desc

Any ideas?
thanks,
freeware
freeware is offline   Fork this post Reply With Quote
Old 11-20-2004, 09:14 AM   #2
freeware
Junior Member
 
Join Date: Nov 2004
Posts: 3 freeware is on a distinguished road
Re: Need results sorted by 2 fields, not 1

Never mind. I got it.
I anyone is interested, here is my solution:

SELECT IF(Date_Submitted > Date_Updated, Date_Submitted, Date_Updated)
as MaxDate, Program_Name, more fields.., from program
Order by MaxDate desc

freeware

Last edited by freeware : 11-20-2004 at 09:29 AM.
freeware is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting only certain fields? Possible? Andreescu SQL syntax 1 11-17-2004 04:47 AM
Assistance with setting up fields, please ChrisJ Looking for an employee or consultant 0 09-20-2004 08:18 PM



All times are GMT -4. The time now is 07:06 PM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".