Jump to content

joins


An7hony

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.