I am trying to get a list of pilots by flightId using a cursor. My select returns all the information I need but it returns records by flightId.
select fp.*, p.*, f.*
from flightPilot fp, pilot p, flight f
where f.FlightStatusId = 2
and fp.pilotId = p.pilotId
and f.flightId = fp.flightId
order by fp.flightId
Ie.
FlightId, PilotId, flightInfo, pilotInfo
1, 5000 ...
1, 5001 ...
1, 5002 ...
1, 7508 ...
2, 6000 ...
2, 6001 ...
2, 6002 ...
2, 8801 ...
I need to use a cursor to get / create the following info so I can use it in an email:
Flight ID: 1, Flight Info
Pilot Id: 5000, Pilot Info
Pilot Id: 5001, Pilot Info
Pilot Id: 5002, Pilot Info
Pilot Id: 7508, Pilot Info
Next flight Id record using a cursor:
Flight ID: 2, Flight Info
Pilot Id: 6000, Pilot Info
Pilot Id: 6001, Pilot Info
Pilot Id: 6002, Pilot Info
Pilot Id: 8801, Pilot Info
Tables:
1) Pilot
pilotId (primary key)
pilotName, address, etc
2) Flight
flightId (primary key)
flightStatusId
flightName, destination, path, etc
3) FlightPilot - index table to see which flights belong to which pilots
flightId
pilotId
select fp.*, p.*, f.*
from flightPilot fp, pilot p, flight f
where f.FlightStatusId = 2
and fp.pilotId = p.pilotId
and f.flightId = fp.flightId
order by fp.flightId
Ie.
FlightId, PilotId, flightInfo, pilotInfo
1, 5000 ...
1, 5001 ...
1, 5002 ...
1, 7508 ...
2, 6000 ...
2, 6001 ...
2, 6002 ...
2, 8801 ...
I need to use a cursor to get / create the following info so I can use it in an email:
Flight ID: 1, Flight Info
Pilot Id: 5000, Pilot Info
Pilot Id: 5001, Pilot Info
Pilot Id: 5002, Pilot Info
Pilot Id: 7508, Pilot Info
Next flight Id record using a cursor:
Flight ID: 2, Flight Info
Pilot Id: 6000, Pilot Info
Pilot Id: 6001, Pilot Info
Pilot Id: 6002, Pilot Info
Pilot Id: 8801, Pilot Info
Tables:
1) Pilot
pilotId (primary key)
pilotName, address, etc
2) Flight
flightId (primary key)
flightStatusId
flightName, destination, path, etc
3) FlightPilot - index table to see which flights belong to which pilots
flightId
pilotId