Thursday, 15 April 2010

How to find the closest dates from MySQL table based on results of another SELECT statement -


I am trying to figure out what is a quick way to get the following results -

  • ID, calendar_date, my_value (some other columns are not relevant here) in Table 2
  • In the Table 2 ID, Event_date, (some other columns are not relevant here) / Ul>

    I want to write a query that selects all IDs and event_dates from Table 1, and table 2 for each event_date Sector is the get nearest Kailender_det like calendar_date event_date at least 30 days before the end, I would like my_value related Kailender_deta that meet your criteria.

    I hope it is clear that I am doing this because (event_date - 30 days) can not exist in Table 2, so it should return the closest available date.

    Even so I have done so far. This question works with hope, but I want to know that this is the fastest way to do this.