n1concepts Posted December 27, 2013 Share Posted December 27, 2013 Hi,I'm trying to define a query that will only pull results for rows where only a specific action is defined for said column (Process) where the 'Action' is 'idle'. Note: if any process as other actions logged, other than 'idle' for any rows of data, then that process should NOT be included in the results at all - only those that do NOT have additional rows logged as 'started' or 'complete'.For example: I need to define the MySQL query that will ONLY parse results that include id 5, 8, 12 being those only show 'Action' of 'idle'.Being all the rest have multple 'Actions' of 'started' or 'complete' - ids: 1,2,3,4,6,7,9,10,11 - then they should be excluded in the 'SELECT' results. ==============================Id Process Action 1 Filter idle 2 Drain idle 3 Swell idle 4 Filter started 5 Stretch idle 6 Filter complete 7 Drain started 8 Spread idle 9 Swell started 10 Swell complete 11 Drain complete 12 Plant idle ============================== I played around with the 'SELECT' statement (defining where 'action != started', etc...) but it pulls the row matching 'idle' - even for those having other actions logged. Again: that's my problem - not sure how to define the logic to exclude those (I even tried subquery to pull all matching 'started' or 'complete' then insert in later query to 'NOT' match on those results but it takes forever to finish the query so know that's not correct. Note: each of the logs have a timestamp - I excluded that column but is apart of each record (just fyi...) I would appreciate some guidance on figuring this out as I'm not sure if 'Case' the correct way to define this logic nor how to defined the query using such... - ensuring any 'process' linked to any other 'Action' other then 'idle' is excluded in the results. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted December 27, 2013 Solution Share Posted December 27, 2013 (edited) SELECT n.id, n.process, n.action FROM n1concepts n LEFT JOIN ( SELECT process FROM n1concepts WHERE `action` <> 'idle' ) as notidle USING (process) WHERE n.action = 'idle' AND notidle.process IS NULL Edited December 27, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.