SQL查询出相同结果报错
select gu_cname from guest where gu_accno=left(a.ac_from,10)and gu_rmno=a.ac_rmno ) as gu_cname
from guest a
当 gu_accno=left(a.ac_from,10)and gu_rmno=a.ac_rmno 返回只有一条记录时正常,有多条相同记录时就报错
有没有什么办法可以让查询出的多个相同结果只返回1个结果?
------解决方案--------------------
SQL code
SELECT gu_cname
FROM guest
WHERE EXISTS ( SELECT 1
FROM guest a
WHERE guest.gu_accno = LEFT(a.ac_from, 10)
AND guest.gu_rmno = a.ac_rmno )