I'm trying to do a single MySQL query to select data inside a third party function, the problem I have however they only pass me the ID. I need to use that ID to select all the related records.
Currently the MySQL statement looks something like this:
SELECT h.id, h.notification_id, h.status, d.detail
FROM headers h, details d
WHERE h.host_id = (SELECT host_id FROM headers WHERE id = '{$rowid}')
AND h.service_id = (SELECT service_id FROM headers WHERE id = '{$rowid}')
AND h.instance = (SELECT instance from headers where id = '{$rowid}')
AND h.id = d.header_id;
Now this works, but I'm thinking the poor MySQL engine is running 3 subqueries because I don't have 3 pieces of information available to me.
So I was wondering if there a way to run this with one query and one subquery to save the load on the database?
Thanks in advance.