1242 - 子查询返回超过1行

时间:2013-12-11 20:09:00

标签: mysql

select `Nom`,`Prenom` from 
`pi_photographes`
where
`IdPhotographe`=(select 
`IdPhotographe`
from`pi_photos`
where`Description`="Site de Palmyre");

基 照片[IdPhoto,FichPhoto,Dimension,Description,IdPhotographe#,RefBien#]

拍摄[IdPhotographe,Nom,Prenom]

1 个答案:

答案 0 :(得分:0)

你需要使用IdPhotographe IN(subquery ...)作为倍数,对于一个,你需要通过在子查询中加上限制来限制你的子查询给出一条记录,而使用=运算符你必须限制你的子查询给出一个结果

一条记录

select `Nom`,`Prenom` from 
`pi_photographes`
where
`IdPhotographe`=(select 
`IdPhotographe`
from`pi_photos`
where`Description`="Site de Palmyre" LIMIT 1);

对于多个记录,请使用IN()

select `Nom`,`Prenom` from 
`pi_photographes`
where
`IdPhotographe` IN (select 
`IdPhotographe`
from`pi_photos`
where`Description`="Site de Palmyre");