Re: SELECT query from two tables

From: Date: Mon, 10 Mar 2008 00:54:43 +0000
Subject: Re: SELECT query from two tables
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-44736@lists.php.net to get a copy of this message
Thanks On Mon, 2008-03-10 at 12:56 +1300, Bruce Cowin wrote: > I think what you mean to do is use IN(). And I would suggest table aliases. So it could look > like this: > > SELECT * FROM ministry_directory md INNER JOIN > ministry_directory_listing_categories mdlc ON md.entry = mdlc.ministry_directory_entry > WHERE md.listing_type = 2 > AND mdlc.ministry_directory_category_reference IN (10, 11) > ORDER BY ministry_directory.name ASC > > > > Regards, > > Bruce > > >>> Ron Piggott <ron.php@actsministries.org> 10/03/2008 10:33:13 a.m. > >>> >>> > I am wondering what is wrong with this syntax? > > SELECT * FROM ministry_directory INNER JOIN > ministry_directory_listing_categories ON ministry_directory.entry = > ministry_directory_listing_categories.ministry_directory_entry WHERE > ministry_directory.listing_type = 2 AND > ministry_directory_listing_categories.ministry_directory_category_reference = 10 AND > ministry_directory_listing_categories.ministry_directory_category_reference = 11 ORDER BY > ministry_directory.name ASC > > It produces 0 results. > > In reality there is presently 1 record that should be found that has > listing_type = 2 and ministry_directory_category_reference 10 and 11 in > the ministry_directory_listing_categories table > > The table "ministry_directory" has the main contact information. entry > is auto_increment; listing_type is an INT(1) column > > The table ministry_directory_listing_categories has 3 columns: > reference which is auto_increment populated; > ministry_directory_entry which is the common field between both tables, > showing what the record belongs to & > ministry_directory_category_reference which is the reference number to > how the directory listing was inputted / categorized. (IE If the person > who completed the form select 2 of the 10 possible categories 2 records > were created.) > > Is there a different way to word my query so I will be able to retrieve > the record with two rows in table ministry_directory_listing_categories > and 1 row in ministry_directory ? > > Thanks for the help guys. > > Ron > >

« previous php.db (#44736) next »