Mysql 初学者SQL单行子查询返回多行?

Mysql 初学者SQL单行子查询返回多行?,mysql,sql,oracle,Mysql,Sql,Oracle,嘿,大家都被这个问题难住了: 显示所有电影标题和dvd编号。按电影名称和dvd排序。Make是为了使电影标题不会在输出中重复 Film_title来自名为cp_title的表,dvd_number来自名为cp_dvd的表。这就是我想到的: select film_title, dvd_number from cp_title join cp_dvd using(title_code) where film_title = (select unique film_title from cp_tit

嘿,大家都被这个问题难住了:

显示所有电影标题和dvd编号。按电影名称和dvd排序。Make是为了使电影标题不会在输出中重复

Film_title来自名为cp_title的表,dvd_number来自名为cp_dvd的表。这就是我想到的:

select film_title, dvd_number
from cp_title
join cp_dvd using(title_code)
where film_title =
(select unique film_title
from cp_title);

在查询中,在
where
子句附近,您正在从
cp\u title

where film_title =(select unique film_title from cp_title)
where
子句需要单行值,而
cp\u title
表将返回多个值,这就是为什么会出现此错误

我不确定您想从查询中获得什么,但假设您需要一组唯一的
电影标题、dvd编号
。然后只需使用
distinct

select distinct film_title, dvd_number from cp_title join cp_dvd using(title_code)
如果

如果返回多行,则无法检查质量

也许你的意思是

select film_title, dvd_number
from cp_title
join cp_dvd using(title_code)
where film_title IN
(select unique film_title
from cp_title);

通过这样做,输出中会重复电影标题。您能否提供表格数据、预期输出和实际输出?@DNkG您需要提供输入和输出示例,以便我们理解您的问题。只需添加一张图片。电影片名列表应该只显示其中一个。@DNkG,如果有多个相同片名,DVD\U号应该显示什么?好问题。老实说,这是我几天来考试的一道练习题。我猜唯一的电影标题栏只有一个dvd号码(可能是第一个)。这就是为什么我在子查询中出现这个错误,因为dvd编号列有多行与电影标题关联?
select film_title, dvd_number
from cp_title
join cp_dvd using(title_code)
where film_title IN
(select unique film_title
from cp_title);