Answer the question
In order to leave comments, you need to log in
How to make a tricky join in MySQL?
There is table1 where the fields
SELECT table1.username, table1.dt, table1.value, table2.value
FROM table1, table2
WHERE table1.username = table2.username and table1.dt БЛИЖАЙШАЯ_К table2.dt
Answer the question
In order to leave comments, you need to log in
SELECT `table1`.`username`, `table1`.`dt`, `table1`.`value`, (
SELECT `table2`.`value`
FROM `table2`
WHERE `table1`.`username` = `table2`.`username`
ORDER BY ABS(TIMESTAMPDIFF(SECOND, `table1`.`dt`,`table2`.`dt`)) ASC
LIMIT 1
) AS `t2value`
FROM `table1`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question