sql - Join tables on nearest date in the past, in MySQL -


I have a SQLite query that I am trying to write Table Test (Sale): ID Sale Date

TableB (Goals): Date of ID Target

I am selecting TableA from this way: Selection ID, Sales, Date Table A

Now on the "hard" part. I need to be included in the query in the tablebag, because I need for each line in the target field table in the table only targets for certain dates in tabby , while All dates in the table are . Therefore, I can not use TableA.date = TableB.date

instead, for each row in the table, I need to match the tablebase with date from the tablebase near the date. I hope I was able to explain what I want. How it can not be understood ..

  SELECT a.id, a sale, aadet, (Select from the Tabs B Top 1 Goal, BWAR Baidet & LT; AADER by DAT DESC) as a target from Table A to  

The closest date in the past


Comments