[英]MySQL select photos linked with a single row from different table
I have 2 tables, one with properties (real estate) and other with all photos for all the properties. 我有2张桌子,一张桌子有物业(不动产),另一张桌子有所有物业的所有照片。 In table photos
I have the link of the photo and ID
of the property. 在表格photos
我具有photos
的链接和该属性的ID
。 In the table of properties
I have all information and the ID
. 在properties
表中,我具有所有信息和ID
。
I need to query all properties and the photos linked to show results... one property all photos. 我需要查询所有属性以及链接以显示结果的照片...一个属性是所有照片。
查询:
SELECT p.*, p1.* FROM photos p, property p1 WHERE p.property_id = p1.property_id;
Try something like this to get a comma separated list of photos 尝试这样的操作以逗号分隔的照片列表
SELECT properties.*, GROUP_CONCAT(photos.photo)
FROM properties
JOIN photos ON properties.id=photos.property_id;
Is that the sort of thing you are looking for? 这是您要找的东西吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.