简体   繁体   中英

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 eg

Activity | Date |

Any help would be awesome! thanks guys/girls

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM