relational algebra for Limit Operator

后端 未结 2 484
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 02:23

What is relational algebra for these two SQL queries:

Select * from film where film_rating = \'PG\' limit 20;

How can we show limit?

         


        
2条回答
  •  情话喂你
    2021-01-21 03:03

    I'm only answering the question about joining here.

    There is a m : n relation between actors and film. It must be realized through an intermediate table, say film_actors. Also the country table probably has a short name like "In" and a long name like "India".

    SELECT film.title, film_actors.role_type, actor.name, country.long_name
    FROM
        film
        LEFT JOIN film_actors ON film.film_id = film_actors.film_id
        LEFT JOIN actor ON film_actors.actor_id = actor.actor_id
        LEFT JOIN country ON actor.country = country.short_name
    

    If the country table has only one column with this short name, then it makes no sense to include it into your query at all. Do it only if country has some additional information that you want to include.

    I used LEFT OUTER JOINS here. They are only requested, if the table on the right side may not always have related records. A cartoon probably has no actors. Otherwise use INNER JOIN

提交回复
热议问题