I found if I divided into 2 steps, I will find the record in table B:

Ta - the given timestamp from table A;

1) select min(abs(Ta - timestamp)) as min_t from B;

2) select * from B where (timestamp + min_t = Ta) or (timestamp - min_t =
Ta);

But, how can I make these 2 steps into 1 query?

Thanks.

Xiaobo

> Hi, all
>
> The version of Mysql is 4.0.15 on Solaris 9. I am in such a situation.
> There are 2 tables something like these:
>
> Table A:
> ----------------------------------
> location|timestamp | other fields
> -------------------------------
>
>
> Table B
>
> --------------------------------
> location|timestamp | other fields
> ---------------------------------
>
> (location. timestamp) make the 'primary key' for each table.
>
> The task is that: the locations are the same, given a timestamp from table
> A, I need to find the record in table B which has the closest timestamp as
> the given one in table A.
>
> I checked the book and research the internet, but didn't find a hint or
> solution yet. Could any one give me a hint please?
>
> Thanks in advance.
>
> Xiaobo
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>
>


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to