I have a MySQL with the following table structure:
table mt_events
id - record id
doc_id - document id
event_id - event id
date - event date
user - user
The problem is that I need a report of all the documents that had an event 3 with a following event 4, which would seem quite an easy simple JOIN, except that one document can have MULTIPLE event 3, which might or might not be followed by event 4... like this:
1 3a 4a 11 12 8 3b 4b 3c 4c 3 17 5
So far I've gotten to :
SELECT ev.date AS Event1, ev.user AS User1, ev2.date AS Event2, ev2.user AS User2
FROM `mt_events` ev
JOIN mt_events ev2 ON ev2.doc_id = ev.doc_id AND ev2.event = 4 AND ev2.date > ev.date
WHERE ev.event = 3 AND ev.date LIKE '2013-03%'
But that doesn't produce required results -
3a 4a
3b 4b
3c 4c
and gives -
3a 4a
3a 4b
3b 4b
3a 4c
3b 4c
3c 4c
Any help would be appreciated...
3the event code andathe document code?3is the event number field (calledevent) andais a symbolic representation ofdate.