is it possible to force a relationship to be one-to-one instead of one-to-many?

Your code generates a cartesian products of both tables. Instead, you need to join, using common column inventory_id to relate the rows of the two tables:

select i.gold, c.char_name
from inventory as i
inner join character as c on c.inventory_id = i.inventory_id

If a character may have more than one match in inventory, aggregation might be necessary:

select sum(i.gold) as gold, c.char_name
from inventory as i
inner join character as c on c.inventory_id = i.inventory_id
group by c.char_name

However this is not what your question suggests. The first query should do what you want.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top