Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Mysql self join to match current record to previous record


deejay - 8:00 pm on Oct 5, 2010 (gmt 0)


DOesn't work in this case Enigma1, as I need all matches, not just one, but only the match where the previous date is immediately prior to the current date.

Yeah, I know.. I confuse myself too.

The query example I gave will produce a result with X rows that matches

Current = Previous
2008-12-04 = 2008-11-20
2009-01-12 = 2008-11-20
2009-01-12 = 2008-12-04
2009-02-04 = 2008-11-20
2009-02-04 = 2008-12-04
2009-02-04 = 2009-01-12

The result set I need to get to is:

Current = Previous
2008-12-04 = 2008-11-20
2009-01-12 = 2008-12-04
2009-02-04 = 2009-01-12

.. of course with the correct readings alongside.

Does that help?


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4211470.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com