Jump to content

Selecting something that is not there

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Lokantis

Lokantis

    Newbie

  • Members
  • PipPip
  • 17 posts
So I have the following tables:

Customer (CustNo, CustFirstName, CustLastName, CustStreet, CustCity, CustState, CustZip, CustBal)

Product (ProdNo, ProdName, ProdMfg, ProdQOH, ProdPrice, ProdNextShipDate)

OrderTbl (OrdNo, OrdDate, CustNo, EmpNo, ShpName, ShpStreet, ShpCity, ShpState, ShpZip)

OrdProd (OrdNo, ProdNo, Qty)

I am trying to do a query as follows:
List all the products (number, name, manufacturer and price) that are never ordered by the 'CO' state customers.

The closest thing that I got was:

SELECT DISTINCT ProdNo, ProdName, ProdMfg, ProdPrice
FROM Product
INNER JOIN OrdProd
ON Product.ProdNo = OrdProd.ProdNo
INNER JOIN OrderTbl
ON OrdProd.OrdNo = OrderTbl.OrdNo
INNER JOIN Customer
ON OrderTbl.CustNo = Customer.CustNo
WHERE ShpState <> 'CO';

I know thats wrong of course. But can someone get me on the right track, I am really confused.

#2
A319

A319

    Newbie

  • Members
  • Pip
  • 1 posts
Firstly theres the maintable from there you are selecting the other information (Product). But I want to know what is included in the other tables and by witch columns it's linked.

MfG

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
SELECT DISTINCT ProdNo, ProdName, ProdMfg, ProdPrice
FROM Product
INNER JOIN OrdProd
ON Product.ProdNo = OrdProd.ProdNo
LEFT OUTER JOIN OrderTbl
ON OrdProd.OrdNo = OrderTbl.OrdNo AND OrderTbl.ShpState='CO'
INNER JOIN Customer
ON OrderTbl.CustNo = Customer.CustNo
WHERE ShpState IS NULL;
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog