Hi All,

I have a question for clearer brains than mine. I would like to join two
tables,. There may be many possible joins in table B to table A, but I only
want to join one row from B to table A - the row with the closest, but
lesser date.

TABLE  A
Row     Id      date
1       46      3 Jan
7       20      10 Jan

TABLE B
Row     Id      date
4       46      1 Jan
5       46      2 Jan
6       46      4 Jan
8       20      8 Jan
10      20      7 Jan
11      20      9 jan

Result
Row 1` in A is joined to row 5 in B
Row 7` in A is joined to row 11 in B

SELECT
a.row,
b.row
FROM
A a
LEFT JOIN B b
ON (a.id = b.id AND a.date > b.date AND <the row with the max dates from the
possible join in b>?)

Any suggestions would be appreciated.

Terry


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

Reply via email to