Forum Moderators: open

Message Too Old, No Replies

Search Query with duplicates. How do I.

Search Query with duplicates

         

RDWest2005

4:33 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



Hello All,
I'm sitting here pulling my hair out :)

I have a massive 2.5+ million listings and have managed to make the seacrh almost instant using MATCH in query...

I'm having a problem pulling back duplicates since they are listings in multiple categories.

I've tried DISTINCT and it works but I think I need to include all fields of the row because i'm returning false $var except those i include in sql like so...

$query = "SELECT DISTINCT bizName,bizAddr,locCounty,bizState
FROM biz_all
WHERE MATCH bizName AGAINST('".mysql_escape_string($keyword)."')
AND
bizState ='state'
ORDER BY bizName
LIMIT $offset, $rowsPerPage";

My main problem is I can't seem to get COUNT and DISTINCT working in same sql query...

$query = "SELECT DISTINCT bizName,bizAddr,locCounty,bizState
COUNT(bizID)
AS numrows

FROM biz_all
WHERE MATCH bizName AGAINST('".mysql_escape_string($keyword)."')
AND
bizState ='state'";

The count comes first for pagination...

Can someone please help me with correcting the sql query?

Thanks,
RD

Clark

11:54 pm on Feb 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried GROUP BY [dev.mysql.com]?