Hi Cindy,
   SELECT Inventory.*, Customer.Name from Inventory Left Join Customer on 
Inventory.PurchasedBy = Customer.ID
    where Inventory.PurchasedBy = Custormer.ID;

   Your query is an equi-join query, which means that there should be data 
for only those rows for which the equality in
the where clause hold.  So it will not show any row in the result if there 
is no a corresponding ID in Customer table for
the PurchasedBy column of the Inventory Table.
Left Join clause forces the query to return a row even if there is no value 
in the second table.

More information can be had from the fine manual or any book on sql.

Anvar.

At 11:12 PM 01/01/2002 -0800, you wrote:

>OK... let's say I have two tables.  Let's say one is an inventory
>table, a bunch of items.  One of the fields is for the inventory
>items that have been sold, and are keys to the second table, which
>is a list of customers; names & addresses.
>
>So let's say I want to pull out all inventory items acquired in
>a particular month.  Some of them have been sold, some have not.
>I want to list them all, and if they've been sold, the names of
>the purchasers, if not, then just blank.
>
>Problem is, of course, when I construct something like
>
>SELECT Inventory.*, Customer.Name WHERE Inventory.PurchasedBy = Customer.ID
>(etc)
>
>I get an ungodly mess for those items with no Customer.Name becasue
>of the way the query is joined(I think that's the right terminology)
>across the tables.
>
>Is there a way around that?  This has got to be a pretty common
>scenario.  I've tried WHERE Inventory.PurchasedBy = Customer.ID OR
>Inventory.PurchasedBy = 0, but that does not help.
>
>Thanks...
>--Cindy
>--
>[EMAIL PROTECTED]
>
>---------------------------------------------------------------------
>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