I have attempted to use inner joins but not sure which would connect where? Do I need to add another FK somewhere?
SELECT user_name, fkbook_id
FROM users
INNER JOIN loans
ON
user_id = fkuser_id
ORDER BY fkbook_id;
i’ve managed to extract the list of all the book_id’s borrowed including any duplicate copies, but not sure how to get the title_name or if this is even possible? Any help/guidance is appreciated
2
Answers
Follow your diagram – you’ll need to
JOIN
through fromloans
->books
->title
:Odd to use varchar fields for the IDs. You’d typically want those to be numeric incrementing values, and if you’re concerned the database might actually get big enough to overflow a multi-billion item integer you use a guid or larger int type. But NOT varchar.
Also odd to use int values for the dates, though MySQL has history here around unix timestamps.