An7hony Posted January 24, 2011 Share Posted January 24, 2011 Hi i am trying to do a join between 2 tables but it is pulling duplicate results. i.e: $query = "SELECT norton_rent.id, norton_rent.Prop_DisplayAddress, norton_rent.Prop_DisplayAddress, norton_rent.Prop_PropType, norton_rent.Prop_Price, norton_rent.Prop_Bedrooms, norton_rent.Prop_Description, norton_rent.Prop_VebraID, norton_rent_img.File_url, norton_rent_img.Prop_VebraID, norton_rent_img.File_index FROM norton_rent LEFT JOIN norton_rent_img ON (norton_rent.Prop_VebraID = norton_rent_img.Prop_VebraID) WHERE norton_rent.Prop_Bedrooms LIKE '%".$_GET['beds']."%' AND norton_rent.Prop_Price < '".$_GET['maxsaleprice']."' AND norton_rent.Prop_VebraID=norton_rent_img.Prop_VebraID AND norton_rent_img.File_index=0 LIMIT ".$offset.", ".$per_page.""; $result = mysql_query($query) or die(mysql_error()); Its ok if i take out WHERE norton_rent.Prop_Bedrooms LIKE '%".$_GET['beds']."%' AND norton_rent.Prop_Price < '".$_GET['maxsaleprice']."' just wondered if anyone can see why? thanks Link to comment https://forums.phpfreaks.com/topic/225485-joins/ Share on other sites More sharing options...
kickstart Posted January 24, 2011 Share Posted January 24, 2011 Hi I would expect each property to have multiple images, and so expect the same property to be brought back multiple times, once for each image. However I can't see anything obvious that would bring back unwanted duplicates. Only odd thing is that you have the JOIN match up in both the ON clause and the WHERE clause. All the best Keith Link to comment https://forums.phpfreaks.com/topic/225485-joins/#findComment-1164390 Share on other sites More sharing options...
An7hony Posted January 24, 2011 Author Share Posted January 24, 2011 i've added GROUP BY norton_rent.Prop_VebraID and its working ok now Thanks Link to comment https://forums.phpfreaks.com/topic/225485-joins/#findComment-1164442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.