Help with query

Posted on 2014-08-04
Last Modified: 2014-08-04
Hi.. I have table with 4 date  fields.
I need to select the field with with most current date and return just the single date.

Data looks like this

FIELD1            FIELD2           FIELD3             FIELD4
1/1/2013      4/4/2013        1/1/2000           8/4/2014

Need to return 1 field with the value 8/4/2014
Question by:JElster
    LVL 28

    Expert Comment

    You can use MAX(...) or order by date desc

    For instance

    SELECT MAX(field1) as field1, MAX(field2) as field2, MAX(field3) as field3, MAX(field4) as field4 from your table.

    or you can select TOP1 field1, field2, field3, field4 from yourtable
    order by field1 DESC
    LVL 6

    Accepted Solution

    Looks like you want to use the GREATEST() function:

    select greatest(field1,field2,field3,field4) as thefield from tbl ;

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
    I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now