I am trying to merge the 2 Selects:
1)
SELECT b.TotalNoAssignedFlights,
a.*, c.*
FROM Flight a, FlightPilot c,
(SELECT count(distinct(FlightId)) TotalNoAssignedFlights from FlightPilot WHERE PilotId = @PilotId) b
WHERE a.FlightId IN (SELECT distinct(lrl.FlightId) from FlightPilot lrl, Flight lr, Pilot l
WHERE lrl.FlightId = lr.FlightId
AND lrl.PilotId = l.PilotId
AND lrl.PilotId = @PilotId --10260
)
AND a.FlightId = c.FlightId
AND c.Pilotid = @PilotId
2)
select top 1 flightStatusTrackingStatusId, *
from flightStatusTracking
where flightId = 1022
and pilotId = 10260
order by flightStatusTrackingId DESC
I am not sure how to to merge these statements as (2) may not return any records or may return many records, and so I use "TOP" and "order by ... DESC"
The merged select should return flightStatusTrackingStatusId from FlightStatusTracking if there is a record or NULL otherwise.
1)
SELECT b.TotalNoAssignedFlights,
a.*, c.*
FROM Flight a, FlightPilot c,
(SELECT count(distinct(FlightId)) TotalNoAssignedFlights from FlightPilot WHERE PilotId = @PilotId) b
WHERE a.FlightId IN (SELECT distinct(lrl.FlightId) from FlightPilot lrl, Flight lr, Pilot l
WHERE lrl.FlightId = lr.FlightId
AND lrl.PilotId = l.PilotId
AND lrl.PilotId = @PilotId --10260
)
AND a.FlightId = c.FlightId
AND c.Pilotid = @PilotId
2)
select top 1 flightStatusTrackingStatusId, *
from flightStatusTracking
where flightId = 1022
and pilotId = 10260
order by flightStatusTrackingId DESC
I am not sure how to to merge these statements as (2) may not return any records or may return many records, and so I use "TOP" and "order by ... DESC"
The merged select should return flightStatusTrackingStatusId from FlightStatusTracking if there is a record or NULL otherwise.