Page 1 of 1

DISTINCT not working right....

Posted: Sun Mar 20, 2011 11:08 am
by psychotomus
I am only trying to get one of each article_id. It seems to be getting the whole database instead.
$sql = "



SELECT DISTINCT article_id, pqdb_articles.*, category_id, category_name, SUBSTRING_INDEX(article_text,' '," . CENTER_COLUMN_PREVIEW . ") AS text



FROM pqdb_articles, pqdb_categories


WHERE article_title LIKE '%$search%' OR article_text LIKE '%$search%'


AND category_id = article_cat ";

Re: DISTINCT not working right....

Posted: Sun Mar 20, 2011 1:54 pm
by McInfo
It will help greatly if you supply the schema and some sample data when asking database-related questions.

Re: DISTINCT not working right....

Posted: Sun Mar 20, 2011 2:15 pm
by Weirdan
psychotomus wrote: DISTINCT not working right....
I am only trying to get one of each article_id. It seems to be getting the whole database instead.
It works exactly how it should: selecting unique rows. If you wanted distinct article_id's you shouldn't have put all other fields there.

Re: DISTINCT not working right....

Posted: Sun Mar 20, 2011 3:57 pm
by John Cartwright
You probably want to remove the DISTINCT in favor of a GROUP BY article_id

Re: DISTINCT not working right....

Posted: Thu Mar 31, 2011 9:01 am
by foxmahesh
you should use group by clause instead of DISTINCT