"Jigal van Hemert" <[EMAIL PROTECTED]> wrote on 01/24/2005 03:10:40 AM:

> > so it will be like this
> > no date price limit
> > 01 1/1/05 5000 100
> > 02 1/2/05 5010 100
> > 03 1/3/05 5020 60 **
> > 04 1/6/05 5010 100 **  there are 3 days difference
> >
> > but how do make a query to check for record no 04 with 03
> > how do i retrieved the 1/3/05 date and the price
> 
> You actually want the latest price before today.
> 
> SELECT * FROM `table_name` WHERE `date` < CURDATE()
> will retrieve all prices before today.
> 
> SELECT * FROM `table_name` WHERE `date` < CURDATE() ORDER BY `date` DESC
> will sort them by date with the latest on top
> 
> SELECT * FROM `table_name` WHERE `date` < CURDATE() ORDER BY `date` DESC
> LIMIT 1
> will only retrieve the latest price before today...
> 
> Regards, Jigal.
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> 


An alternative query to Jigal's would be:

SELECT MAX(`date`) as `lastdate` from `table_name` where `date` < 'target 
date' 

but use the actual current sales date ('2005-01-06' in your example) in 
place of 'target date'.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to