[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Help with query

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
0
JElster
Asked:
JElster
1 Solution
 
sammySeltzerCommented:
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
0
 
rjohnsonjrCommented:
Looks like you want to use the GREATEST() function:

http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_greatest

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

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now