从m_cast中选择DISTINCT pid,其中mid =(从电影中选择标题为“ anand”的mid)

时间:2019-06-27 17:04:42

标签: sql

select name from person where pid ? (select DISTINCT pid from m_cast where mid =(select mid from movie where title like 'anand'))

select DISTINCT pid from m_cast where mid =(select mid from movie where title like 'anand')

返回多个值,但是当作为内部查询传递给主查询时,它没有给出任何结果

2 个答案:

答案 0 :(得分:0)

您可以使用联接并避免使用= (subquery)

  select DISTINCT pid 
  from m_cast 
  inner join  movie on movie.mod= m_cast.mid and  movie.title   like 'anand'

  select name 
  from person 
  inner join  (
    select DISTINCT pid 
    from m_cast 
    inner join  movie on movie.mod= m_cast.mid and  movie.title   like 'anand'
  ) t on t.pid = person.pid

答案 1 :(得分:0)

SELECT p.Name 
FROM Person p WHERE p.PID IN
    (SELECT TRIM(mc.PID)
    FROM M_Cast mc JOIN Movie m
    ON mc.MID = m.MID
    WHERE m.title = 'Anand')