Re: Finding the records that are NOT linked

From: Date: Wed, 18 Apr 2001 20:42:01 +0000
Subject: Re: Finding the records that are NOT linked
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49261@lists.php.net to get a copy of this message
"Simon Kimber" <simon@funny.co.uk> wrote: > I have written a PHP/MySQL "top-sites" program. It has two tables, > link_sites, which contains the details of all the sites signed up > (ID,url,title,description) and link_stats in which a new record is inserted > every time a visitor links in from one of those sites > (ID,siteID,clientIP,datestamp). > > Can anyone help me write a SQL query to pull out all the sites in link_sites > that are not mentioned in link_stats.. ie the ones that have never been > clicked.. Read the manual about LEFT JOIN syntax. In a nutshell you need something like: SELECT * FROM link_sites LEFT JOIN link_stats ON link_sites.ID=link_stats.ID WHERE link_stats.ID IS NULL In regular language, it means: Look through *all* of the records from link_sites, join them with records from link_stats with an ID that matches the ID from link_sites and then only show records where there isn't a matching record in link_stats (in which case it's NULL). -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/

« previous php.general (#49261) next »