Page 1 of 1

Mysql: Ignoring Duplicate Columns

Posted: Mon Nov 03, 2008 4:57 pm
by katlis
Here's what I'm working on:

Code: Select all

 
$keyword = "blah";
 
$query = "SELECT *, ( (1.3 * (MATCH(title) AGAINST ('$keyword' IN BOOLEAN MODE))) + (0.6 * (MATCH(url,description) AGAINST ('$keyword' IN BOOLEAN MODE))) ) AS relevance FROM pages WHERE ( MATCH(url,title,description) AGAINST ('$keyword' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC";
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
$url = $row['url'];
$title = $row['title'];
echo "<a href=$url>$title</a><br>";
}
 
Now, some rows in table 'pages' have the same 'title' (they have the same 'description' too, just a slightly different 'url'). I do not want to display rows that share the same 'title', just one will do. How should I go about doing this? Can I do it in the query? I should mention that it does not matter which row is chosen and which are ignored... just need one of them.

Thanks for the help.

Re: Mysql: Ignoring Duplicate Columns

Posted: Mon Nov 03, 2008 5:06 pm
by infolock
you should look into using GROUP BY then if you don't want other rows who share the same title to display.

Re: Mysql: Ignoring Duplicate Columns

Posted: Mon Nov 03, 2008 8:43 pm
by katlis
Thanks infolock,
Any chance you can show me where to put GROUP BY title (I assume)? Not having any luck here with the syntax.

Re: Mysql: Ignoring Duplicate Columns

Posted: Wed Nov 05, 2008 4:05 pm
by infolock

Code: Select all

 
 
query = "SELECT *, ( (1.3 * (MATCH(title) AGAINST ('$keyword' IN BOOLEAN MODE))) + (0.6 * (MATCH(url,description) AGAINST ('$keyword' IN BOOLEAN MODE))) ) AS relevance FROM pages WHERE ( MATCH(url,title,description) AGAINST ('$keyword' IN BOOLEAN MODE) ) HAVING relevance > 0 group by title ORDER BY relevance DESC";
 
 

Edit: just a question here....why are you issuing this query this way? is your table schema (no offense) that jacked up? just curious...