user1043646
user1043646

Reputation:

MySQL Join assistance

img

Hey guys I am struggling to create a query which gives schedule of a pilot for a given day. So far I've got

SELECT f.flight_date, l.lesson_date FROM Flight f JOIN lesson l ON f.pilot_idpilot = l.pilot_idpilot WHERE f.flight_date = CURDATE() OR l.lesson_date = CURDATE() AND pilot_idpilot = 7236;

The result I get is

Lesson_id | lesson_date | pilot_idpilot | idFlight | flight_date | pilot_id_pilot

Is there a way just to specify the type of activity the pilot is involved in e.g.

Activity | Date |

Any help would be awesome! thanks guys/girls

Upvotes: 1

Views: 39

Answers (1)

JohnFx
JohnFx

Reputation: 34909

How about this:

SELECT 'Lesson' as Activity, lesson_date as Date
FROM Flight f JOIN lesson l ON f.pilot_idpilot = l.pilot_idpilot 
WHERE l.lesson_date = CURDATE() AND pilot_idpilot = 7236
UNION
SELECT 'Flight' as Activity, flight_date as Date
FROM Flight 
WHERE f.flight_date = CURDATE() AND pilot_idpilot = 7236;

Upvotes: 1

Related Questions