我试图在PostgreSQL 9.2中执行以下SQL语句,但它失败并出现错误:
SELECT "TrainingName" FROM "HSETrainingName" WHERE "ID" =
SELECT "trainingID" FROM "HSEGroupedTraining" WHERE "groupID" =3
第二个select语句返回多个值。怎么解决?
答案 0 :(得分:2)
您可以使用IN
构建:
SELECT "TrainingName"
FROM "HSETrainingName"
WHERE "ID" IN (SELECT "trainingID"
FROM "HSEGroupedTraining"
WHERE "groupID" = 3)
答案 1 :(得分:0)
使用子查询和IN:
SELECT "TrainingName"
FROM "HSETrainingName"
WHERE "ID" IN
(SELECT "trainingID"
FROM "HSEGroupedTraining"
WHERE "groupID" =3)