relational algebra for Limit Operator

柔情痞子 提交于 2019-12-01 23:41:06

About the limit in relational algebra. Traditional relational algebra does not support anything like the limit in SQL. This problem has been recognized and studied by Li, Chang, Ilyas and Song in RankSQL: query algebra and optimization for relational top-k queries (SIGMOD 2005). They have proposed a monotonic scoring function F that ranks the results by the sorting operator tauF.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!