I am using distinct in select query of mysql database like this
$query=mysql_real_escape_string($_GET['query']);
$query_for_result=mysql_query("SELECT DISTINCT *
FROM vendor
LEFT JOIN branches ON branches.vendor_id = vendor.vendor_id
WHERE
(vendor.name LIKE '%".$query."%'
OR vendor.description LIKE '%".$query."%'
OR branches.city LIKE '%".$query."%')");
$qrow=mysql_fetch_array($query_for_result);
if(empty($qrow)){
while($qrow=mysql_fetch_array($query_for_result)){
Some Code to display result
<?php
}
mysql_close();
}
?>
Problem is this, it display every result many time , It display every result as many as it fond city from branches table , (Means: if a result in vendor table has 5 cities in branches table it will display 5 time)
It is working. What you’re returning is all the column values from both tables. so if a vendor has 5 cities, then there are 5 distinct results:
None of these rows are the same, therefore, they ARE the distinct results of the query.
Assuming you’re wanting the distinct list of vendors, then you need to so something like: