SQL: Syntax error with intersect?

后端 未结 6 2073
北恋
北恋 2020-12-06 17:27

This is my query:

-- Sids of suppliers who supply a green part AND a red part
(SELECT Suppliers.sid
FROM Suppliers
JOIN Catalog ON Catalog.sid = Suppliers.si         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 18:00

    Another solution in order to use INTERSECT in MySQL is to use IN clause. Problem: "Find course id’s of courses offered in Fall 2009 and Spring 2010"

    //DML sample
    (select course_id
    from section
    where semester = ‘Fall’ and year = ‘2009’)
    intersect
    (select course_id
    from section
    where semester = ‘Spring’ and year = ‘2010’);
    

    In MySQL:

    select distinct course_id
    from section
    where semester = 'Fall' and year= 2009 and
    course_id in (select course_id
    from section
    where semester = 'Spring' and year= 2010);
    

    If you need more on IN clause , please search on Google.

提交回复
热议问题