0

When I try below code I got error like

"ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'intersect select sc1.section_identifier,sc2."

and I searched in internet and found new fact that mysql doesn't support intersect operation. How can I fix my code having same function with 'intersect'. Please help me!!

select g1.section_identifier, g2.section_identifier
from grade_report g1, grade_report g2
where g1.student_number=g2.student_number and  
g1.section_identifier<g2.section_identifier
intersect
select sc1.section_identifier,sc2.section_identifier
from section sc1, section sc2
where sc1.course_number=sc2.course_number and     
sc1.section_identifier<sc2.section_identifier;
Dkyo Jeong
  • 25
  • 2
  • Possible duplicate of [Alternative to Intersect in MySQL](http://stackoverflow.com/questions/2621382/alternative-to-intersect-in-mysql) – philipxy Nov 13 '16 at 12:48
  • In relational algebra, INTERSECT is just NATURAL JOIN for two relations with the same attributes. In MySQL: If you want equality of same-named columns then just use NATURAL JOIN. INTERSECT (like UNION) pairs up columns by order and uses the columns of the left argument in the same order in the result. So you can JOIN ON equality of columns in order and SELECT L.* where L is the left table alias. You can also use IN & EXISTS because queries with these can be rewritten with JOIN & vice versa. Then you can just use SELECT *. But IN also requires writing column names. So you might prefer EXISTS. – philipxy Nov 13 '16 at 14:20

0 Answers0