How can I write a query to exclude rows in a table?

How do I  exclude those rows where crew job for a particular char_trip, such as 10003  is both pilot and copilot from the table data below? I was trying to do something like the attached code snippet.

CHAR_TRIP      EMP_NUM      CREW_JOB
10001      104      Pilot
10002      101      Pilot
10003      105      Pilot
10003      109      Copilot
10004      106      Pilot
10005      101      Pilot
10006      109      Pilot
10007      104      Pilot
10007      105      Copilot
10008      106      Pilot
10009      105      Pilot
10010      108      Pilot
10011      101      Pilot
10011      104      Copilot
10012      101      Pilot
10013      105      Pilot
10014      106      Pilot
10015      101      Copilot
10015      104      Pilot
10016      105      Copilot
10016      109      Pilot
10017      101      Pilot
10018      104      Copilot
10018      105      Pilot
SELECT DISTINCT (CHARTER.CHAR_TRIP) AS [CHAR_TRIP], REPLACE(CONVERT(VARCHAR(9),CHAR_DATE,6),' ', '-'), 
CHARTER.AC_NUMBER, MODEL.MOD_NAME, EMPLOYEE.EMP_LNAME, CREW.CREW_JOB
FROM MODEL INNER JOIN AIRCRAFT ON MODEL.MOD_CODE = AIRCRAFT.MOD_CODE 
INNER JOIN CHARTER ON AIRCRAFT.AC_NUMBER = CHARTER.AC_NUMBER 
INNER JOIN CREW ON CHARTER.CHAR_TRIP = CREW.CHAR_TRIP
INNER JOIN EMPLOYEE ON CREW.EMP_NUM = EMPLOYEE.EMP_NUM
WHERE (((CREW.CREW_JOB)<>'CoPilot'))
MINUS
SELECT COUNT(DISTINCT (CHAR_TRIP)) AS [Number of Trips],CHAR_TRIP
FROM CREW
GROUP BY CHAR_TRIP
HAVING Count(CHAR_TRIP) >1;

Open in new window

Barbara69Asked:
Who is Participating?
 
fanopoeCommented:
select *
from YourTable
where CHAR_TRIP not in(select CHAR_TRIP
from your table
where CREW_JOB = 'Pilot' and CHAR_TRIP in(select CHAR_TRIP
from your table
where CREW_JOB = 'Copilot')



hth
0
 
Barbara69Author Commented:
Thank you, so very much for your assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.