Hi all and thanks for reading my problem.
Background:
I'm trying to output results from 2 queries into one page and I simply can't get my head round it. I'm hoping that someone can enlighten me or at least point me in the right direction.
OK now for the queries.
I have two:
First one gets me the members I want along with their ID's that I can use for the second query.
SELECT pilots.id, reports.id, MAX(reports.datefiled) AS lastfiled, pilots.id, pilots.name, pilots.country, pilots.hub, pilots.status, pilots.fpi, pilots.ivao, pilots.vatsim, reports.id, reports.duration, reports.result, pilots.rank, pilots.admission_date
FROM pilots, reports
WHERE pilots.id = reports.id AND result='Completed' AND purpose NOT LIKE 'GA' AND reports.datefiled > '2008-07-01 00:00:00'
GROUP BY reports.id
ORDER BY reports.id asc
This one does an extra bit of math required. It basically add all their hours that have been accepted along with total distance and fuel.
SELECT COUNT(reports.id) AS T_PIREPS, SEC_TO_TIME( SUM( TIME_TO_SEC(reports.duration))) AS T_TIME, SUM(reports.distance) AS T_DIST, SUM(reports.fuel) AS T_FUEL
FROM pilots, reports
WHERE pilots.id = reports.id AND result='Completed' AND purpose NOT LIKE 'GA'
GROUP BY reports.id
ORDER BY reports.id asc
The problem:
What I'm trying to do is to have the second query nested in the first so all members who fall within the date criteria (depending on 'datefiled' field) will be returned and also have their details returned in full for their entire history, not just the period from 'datefiled'.
The first query gathers all the standard info and the second does the math.
From what I've been reading up on, subqueries seems to be the way to do it, however, for the life of me I just can't seem to get the syntax right. Would anyone be able to give me a hand?
Cheers
Steph.