I have movie database with following tables:
Movies:
mid | title
-----+---------
9 | Jason X
Actors:
mid | name
----+------------
9 | Kane Hodder
9 | Lexa Doig
My question is what is best practice to get all data related to particular movie from all tables, On my opinion getting the data on one sql query is ideal, so I don't have to do multiple queries to db for each table.
When I tried to get everything in one query, I get duplicate data, for example I get title and mid on every row, while it's needed only one time:
mid | title | name
---------------+------------
9 | Jason X | Kane Hodder
9 | Jason X | Lexa Doig
The webapp will convert Postgres output to a hash like:
movie => {mid => 9, title => 'Jason X', actors => ['Kane Hodger', 'Lexa doig']}
With current postgres output I get duplicate data for instance $movie{title} equals to ['Jason X', 'Jason X'], where needed only 'Jason X'