select
s.id,
s.name,
c.PNAME city,
s.user_name,
s.logo,
sqrt(pow((latitude-'1'),2)+pow((longitude-'1'),2)) as distance ,
(SELECT
ph.phone_number
FROM `phones` as ph
WHERE (ph.type='tel' AND ph.`shop_id`=s.id)) as phons
from shops as s
JOIN addresses as a ON s.address_id=a.id
JOIN city as c ON c.id=a.city
where 1
order by('distance ASC')
limit 0,20 ;
以上code
给我一个error
:
错误代码1242,SQL状态21000:子查询返回多于1行
答案 0 :(得分:2)
select s.id,s.name,
c.PNAME city,s.user_name,s.logo,
sqrt(pow((latitude-'1'),2)+pow((longitude-'1'),2)) as distance ,
((SELECT GROUP_CONCAT(ph.phone_number) FROM `phones` as ph WHERE (ph.type='tel'))) as phons
from shops as s
JOIN addresses as a ON s.address_id=a.id
JOIN city as c ON c.id=a.city
where 1
order by('distance ASC')
limit 0,20 ;
GROUP_CONCAT reult numberphone in row
答案 1 :(得分:1)
在
等子查询中使用limit 1
SELECT ph.phone_number FROM `phones` as ph
WHERE (ph.type='tel' AND ph.`shop_id`=s.id limit 1