I’m stuck trying to remove the nested part from the following query :
SELECT DISTINCT * FROM `audit` WHERE action_performed = 'REJECTED' AND `event_id` IN (
SELECT DISTINCT event_id AS `Count`
FROM `audit`
WHERE username = 'someUser'
AND action_performed IN ('SUBMITTED_FOR_APPROVAL', 'SAVED_AND_APPROVED')
AND (action_timestamp >= '2012-01-12 00:00:00' AND action_timestamp <= '2012-01-24 23:59:59'))
Basically, I’m trying to fetch the number of rejected events by a user, that were submitted by him before. I determine this by the action_performed column which takes values such as
SUBMITTED_FOR_APPROVAL, SAVED_AND_APPROVED and REJECTED.
The reason I want to remove the nested part is because the audit table currently contains over 100k rows, and the result of the nested query itself is around 2000 rows, so the query always times out.
I’ve tried searching on the site, and doing an INNER JOIN as suggested in some questions, but maybe I was doing it wrong!
Thank you.
EDIT – The audit table structure is as follows
Field Type
id int(11)
username varchar(100)
event_id int(11)
action_performed varchar(100)
action_timestamp timestamp
1 Answer