Selecting rows from one table using values gotten from another table MYSQL

前端 未结 5 586
暗喜
暗喜 2021-02-07 07:48

I have currently have 2 mysql tables in my db

Film and Film_Ratings_Report

The primary key for Film is filmid which is u

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 08:41

    Preferred solution for this is to use join, and don't forget group by so that you don't have duplicate lines:

    select film.*
    from film
    join film_rating_report on film.filmid = film_rating_report.filmid
            and rating = 'GE'
    group by film.filmid
    

    EDIT: as correctly noted by @ypercube, I was wrong claiming that the performance of join & group by is better than using subqueries with exists or in - quite the opposite.

提交回复
热议问题