I have this query:
$relevantwords = {"one" , "two" , "three" } ;
foreach ($relevantwords as $word)
{
$query .= "SELECT * FROM delhi_items WHERE heading like '%$word%' AND id!={$entry_row['id']} AND visible=1 UNION ALL " ;
}
$query = implode( " " , explode(" " , $query , -3) ) ;
$query .= " ORDER BY time_stamp DESC LIMIT 0, 20 " ;
$result_set = mysql_query($query, $connection);
This causes several duplicates in my resultset. Is there a way to detect and remove these duplicates from the resultset ? I know I should probably try to avoid the duplicates in the first place, but I am unable to figure that out.
Also I tried distinct keyword, it didn’t work (because its a loop, the same entry is fetched again and again).
Laslty I am kind of an amateur so please tell me if I am doing something fundamentally uncool with such a long sql query in a for loop.
Thanks
I would try to have one
SELECTand noUNIONandDISTINCT. It will probably be a faster query: