Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT from two same table with intersect

The query:

SELECT id_user 
  FROM Rating 
 Where id_movie=2 
INTERSECT 
SELECT id_user 
  FROM Rating 
 Where id_movie=3

but I get:

1064 - 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 id_user FROM Rating Where id_movie=3 LIMIT 0, 30' at line 1

any have solution??

like image 580
dito Avatar asked Mar 13 '26 03:03

dito


1 Answers

Following query will do ..

SELECT id_user 
FROM Rating 
Where id_movie=2 and id_user in 
             ( SELECT id_user FROM Rating Where id_movie=3);
like image 113
nayakam Avatar answered Mar 14 '26 17:03

nayakam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!