Darren,

> I need to construct a query to find out what customers in the database
> have not
> booked shipments with us. That means there would be no
> records in the shipment table for a given customer id.

If I get this right, it should be:

SELECT custid, name FROM customers LEFT JOIN shipment ON custid = customerid
WHERE shipmentid IS NOT NULL

or:

SELECT custid, name FROM customers INNER JOIN shipment ON custid =
customerid

Regards,
--
  Stefan Hinz <[EMAIL PROTECTED]>
  CEO / Geschäftsleitung iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Telefon: +49 30 7970948-0  Fax: +49 30 7970948-3


----- Original Message -----
From: "Darren Young" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 16, 2002 11:24 PM
Subject: RE: SQL Question


>
> I have 2 tables in our MySQL database like this:
>
> TABLE: customers
> +------------------+-----------------------+------+-----+---------+-----
> -----------+
> | Field            | Type                  | Null | Key | Default |
> Extra          |
> +------------------+-----------------------+------+-----+---------+-----
> -----------+
> | custid           | mediumint(8) unsigned |      | PRI | NULL    |
> auto_increment |
> | name             | tinytext              | YES  |     | NULL    |
> |
> | email            | tinytext              | YES  |     | NULL    |
> |
> | company          | tinytext              | YES  |     | NULL    |
> |
> +------------------+-----------------------+------+-----+---------+-----
> -----------+
>
>
> TABLE: shipment
> +---------------------+-----------------------+------+-----+---------+--
> --------------+
> | Field               | Type                  | Null | Key | Default |
> Extra          |
> +---------------------+-----------------------+------+-----+---------+--
> --------------+
> | shipmentid          | mediumint(10)         |      | PRI | NULL    |
> auto_increment |
> | origin              | mediumint(10)         | YES  |     | NULL    |
> |
> | destination         | mediumint(10)         | YES  |     | NULL    |
> |
> | quoteid             | mediumint(10)         | YES  |     | NULL    |
> |
> | customerid          | mediumint(10)         | YES  |     | NULL    |
> |
> | carrierid           | mediumint(10)         | YES  |     | NULL    |
> |
> +---------------------+-----------------------+------+-----+---------+--
> --------------+
>
> I need to construct a query to find out what customers in the database
> have not
> booked shipments with us. That means there would be no
> records in the shipment table for a given customer id. I can
> easily get a count of how many shipments are there for
> customers that have booked (via count() and group), but this
> one is eluding me..
>
> Any help or suggestions on where to get more info would be
> appreciated.
>
> Thanks,
>
> Darren Young
> The Freight Depot
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to