Solved

SQL join returning all not

Posted on 2009-07-14
3
212 Views
Last Modified: 2012-05-07
This is for Oracle.
I need to select the drawings that are NOT in the packlist table.
In other words, drawings that have no packlists.
This returns 91 rows, but there should only be about 3.
It returns all the drawing numbers multiple times.
I don't know how to do an inner join in oracle.
Can you help? Thanks! Beth
SELECT DRAWING.DRAWING, CUSTOMER.CUSTOMER_NAME, DRAWING.CUSTOMER_PART_NO
FROM CUSTOMER, DRAWING, PACKLIST
WHERE  DRAWING.DRAWING <>PACKLIST.DRAWING
AND CUSTOMER.CUSTOMER_NO = DRAWING.CUSTOMER_NO;

Open in new window

0
Comment
Question by:ba_trainer
3 Comments
 
LVL 17

Accepted Solution

by:
pssandhu earned 500 total points
ID: 24852802
Something like:
SELECT  DRAWING.DRAWING, CUSTOMER.CUSTOMER_NAME, DRAWING.CUSTOMER_PART_NO
FROM    CUSTOMER, DRAWING
WHERE   CUSTOMER.CUSTOMER_NO = DRAWING.CUSTOMER_NO
        AND DRAWING.DRAWING NOT IN (SELECT Drawing From PackList)

Open in new window

0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24852816
Hope this helps:
SELECT DRAWING, CUSTOMER.CUSTOME, DRAWING.CUSTOME
FROM CUSTOMER 
INNER JOIN DRAWING ON CUSTOMER.CUSTOMER_NO = DRAWING.CUSTOMER_NO
LEFT OUTER JOIN PACKLIST ON DRAWING.DRAWING = PACKLIST.DRAWING
WHERE PACKLIST.DRAWING IS NULL

Open in new window

0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24852825
Inner join plus a check for non-existance would be something like:

SELECT DRAWING.DRAWING, CUSTOMER.CUSTOMER_NAME, DRAWING.CUSTOMER_PART_NO
FROM CUSTOMER INNER JOIN DRAWING ON DRAWING.CUSTOMER_NO = CUSTOMER.CUSTOMER_NO
WHERE NOT EXISTS (SELECT 1 FROM PACKLIST WHERE DRAWING.DRAWING = PACKLIST.DRAWING)
;
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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