?
Solved

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

Posted on 2008-11-07
2
Medium Priority
?
285 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Barbara69
2 Comments
 
LVL 11

Accepted Solution

by:
fanopoe earned 2000 total points
ID: 22906094
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
 

Author Closing Comment

by:Barbara69
ID: 31514427
Thank you, so very much for your assistance.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question