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

前端 未结 5 662
暗喜
暗喜 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:30

    I believe this will work, thought without knowing your DB structure (consider giving SHOW CREATE TABLE on your tables), I have no way to know for sure:

    SELECT film.*
    FROM (film)
    LEFT JOIN film_rating_report ON film.filmid = film_rating_report.filmid AND film_rating_report.rating = 'GE'
    WHERE film_rating_report.filmid IS NOT NULL
    GROUP BY film.filmid
    

    (The WHERE film_rating_report.filmid IS NOT NULL prevents lines that don't have the rating you are seeking from sneaking in, I added GROUP BY at the end because film_rating_report might match more than once - not sure as I have visibility to the data stored in it)

提交回复
热议问题