Question : mysql join 2 tables

Hello experts

I have 2 tables relating to properties, for each property there is one row in propslist and multiple rows for the images in the table propphotos:

propslist:
      id
      location
      price
      bedrooms
      etc.


propphotos:
      id
      property_id
      photo_order_number
      photo_name
      caption

I would like to know if it is possible with a mysql join statement to select all the column data for properties from propslist along with multiple photo details (maximum of 5 per property 'photo_name' & 'caption')  for each property from propphotos ordering the photos by their photo_order_number.

Is this possible? if so could you help me out with the mysql statement please or alternatively suggest the best method to achieve the same outcome?

Many thanks

Answer : mysql join 2 tables

This selects all the properties and the images that are associated with each property.  If you just want all the photos for an individual property then add something like:   WHERE propslist.id = 'somevalue'  just before the ORDER BY line.
1:
2:
3:
4:
SELECT propslist.*, propphotos.* FROM propslist
LEFT JOIN propphotos
ON propphotos.property_id = propslist.id
ORDER BY propphotos.photo_order_number;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us