Re: Urgent JOIN help needed

From: Date: Sat, 31 Jul 2004 04:21:16 +0000
Subject: Re: Urgent JOIN help needed
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-35502@lists.php.net to get a copy of this message
On Fri, 30 Jul 2004 23:25:57 -0400, Chris Payne <chris_payne@planetoxygene.com> wrote: > Hi there everyone, > > I'm new to JOINS and have followed some info in the MySQL manual but I'm at > a loss, using the code I'll paste below, I get each result 4 times and I am > confused as to why? Basically I'm trying to display ALL fields from the > vendorprices table, and grab just the Description column from the fooditems > table, the factor which joins them both is the string $VendorID which in the > vendorprices table is VendorNumber and in the fooditems table is > CategoryNumber. > > $sql = "SELECT * FROM vendorprices LEFT JOIN fooditems on > (vendorprices.VendorNumber = fooditems.CategoryNumber AND > fooditems.CategoryNumber = '$VendorID') WHERE > vendorprices.VendorNumber='$VendorID' AND > fooditems.CategoryNumber='$VendorID'"; > > Can anyone see where I'm going wrong? This is driving me nuts and I need to > figure it out urgently. > You should / can only join ON columns. You're putting "fooditems.CategoryNumber='$VendorID'" twice, you only need / should have it in the WHERE clause. -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.db (#35502) next »