Hello, there is a related table with movie_name fields | seller_name | unique_id. This table was obtained by combining the sellers and movies tables across the unique_id field. In this table, I have several identical id in the field unique_id. It is specially made. I need to select everyone who has the same id. Here is what I tried:

SELECT p.seller_name , s.movie_name FROM sellers p INNER JOIN movies s ON p.unique_id = s.unique_id HAVING COUNT(*) > 1; 

But this query generally produces an incorrect result; it does not display fields with the same id. Tell me how to create a request then?

  • And in what table are there several records with one unique_id in sellers or in movies? For identical unique_id, the values ​​seller_name and movie_name are the same or different? Maybe you need to add some group by or first get a list of non-unique in the IN - Mike subquery
  • @Mike in the table movies with several unique_id with one, but the search should be carried out in the combined. The values ​​seller_name and movie_name are of course different: the name of the seller and the name of the movie, I just get that several films are matched with the same last name. And I want to display these names with the films - M-Misha-M

1 answer 1

 SELECT p.seller_name , s.movie_name FROM sellers p INNER JOIN movies s ON p.unique_id = s.unique_id WHERE p.unique_id IN( SELECT unique_id FROM movies GROUP BY unique_id HAVING COUNT(*) > 1 ) 
  • oh klas, thanks for what you need - M-Misha-M