Re: SQL : multiple SELECT and missing rows.

From: Date: Tue, 03 Apr 2001 01:52:46 +0000
Subject: Re: SQL : multiple SELECT and missing rows.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-46743@lists.php.net to get a copy of this message
"Maxim Maletsky" <maxim.maletsky@japaninc.net> wrote: > As you can see, the main data is in 'accounts', the 'addresses.ID' is UNIQUE > and corresponds to 'accounts.ID'. The fact is that not every account has an > address registered with it. <snip> > FROM > accounts, > addresses You're doing a straight join. You need to use a LEFT JOIN to return all the records from one table and those from a second table that match based on a common field. Read about joins in the manual and find a resource on SQL statements - it'll pay off. SELECT * FROM accounts LEFT JOIN addresses ON addresses.ID = accounts.ID > Can anyone suggest me how do I SELECT ALL of the accounts having simply NULL > on 'addresses.*' when there's no such row, instead of 'loosing' the > whole > 'account' row? Use the query above and add: WHERE addresses.ID IS NULL -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/

« previous php.general (#46743) next »