我有这个MySQL查询效果很好,我只需要为advantages.value
中的每个ID抓取properties.advantages.
正如您在图片中看到的那样,列优势很明确(至少对我而言,我没有创建这个),ID由-
分隔。我怎样才能获得这些价值观?
SELECT
properties.id,
(SELECT types.value FROM types WHERE types.id = properties.type_id) as types,
properties.price,
properties.town_id,
**( SELECT advantages......),**
towns.id,
towns.value
FROM properties
LEFT JOIN towns
ON properties.town_id=towns.id
WHERE properties.published='1'
答案 0 :(得分:1)
我猜这是和你一起遇到麻烦的?
**( SELECT advantages......),**
您可以LIKE
与CONCAT()
一起使用来比较它们:
SELECT a.advantagesCol FROM advantages a
WHERE CONCAT('-',properties.id,'-') LIKE a.Id_Column