Link to home
Start Free TrialLog in
Avatar of gingera
gingera

asked on

PHP MYSQL: How to retreive (1) latest date, (2) value associated with latest date, (3) largest value (4) lowest value?

PHP MYSQL

Hello,

I have a MySQL database table I want to retrieve data from.

The format is
[ Date ] [ Value ]

I want to retrieve 4 things from the table:
1. The latest date (call it $latest_date)
2. The value associated with the latest date (call it $latest_value)
3. The highest value in the column Value (call it $max_value)
4. The lowest value in the column Value (call it $min_value)


How do I write in my PHP script a MySQL query to retrieve those 4 things?


Thanks.
Avatar of Rob Siklos
Rob Siklos
Flag of Canada image

Here's the SQL:

1 and 2:
  SELECT `Value`, `Date`
  FROM table
  HAVING `Date` = MAX(`Date`)

3:
  SELECT MAX(`Value`) FROM table

4:
  SELECT MIN(`Value`) FROM table
ASKER CERTIFIED SOLUTION
Avatar of Rob Siklos
Rob Siklos
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gingera
gingera

ASKER

THANKS