I have a problem with joining 2 tables together, as follows
Table 'jobs'
id int(20) auto_increment PK
name varchar(200)
Table 'logs'
id int(20) auto_increment PK
job_id int(20) FK(events.id)
event varchar(200)
I want all unique ID's that have a log entry for logs.event = 'initialized' AND logs.event = 'failed'
How can I do this with MySQL?
I’ve tried this query, but it won’t work (Query succeeded, 0 results, while there are results that match in the DB)
SELECT
a.id,
a.name
FROM
jobs as a
RIGHT OUTER JOIN logs b ON b.job_id = a.id
WHERE
b.event = 'initialized'
AND
b.event = 'failed'
Try this instead
Basically I’m assuming that any single log can’t be both “initialised” AND “failed” at the same time – so you have to join twice and test two separate log entries… ?
Edit: update with suggestions in comments.