Queries should have been:
SELECT collection_title, image_title FROM collection LEFT JOIN image ON collection.collection_id = image.collection_id;
SELECT image_title, collection_title FROM image LEFT JOIN collection ON image.collection_id=collection.collection_id;
The exercises for the last two units using SQL have been relatively easy to learn and use. However, I know I do not completely understand JOIN because although I was able to create queries which produce results, they were not the results I expected, and I'm not yet sure why. I'll be looking at it again later today in order to have queries to submit for the assignment, but I'll post here the ones I first did, then follow with the query which gave me the results I was looking for (which was not a JOIN query).
SELECT collection_title, image_title FROM collection LEFT JOIN image ON collection.collection_id = image.image_id;

SELECT image_title, collection_title FROM image LEFT JOIN collection ON image.image_id=collection.collection_id;

Here's what I was trying to get:

And here is the query used:
SELECT image_title , collection_title FROM image , collection WHERE image.collection_id = collection.collection_id ORDER BY collection_title;
So, as I said, I haven't quite got the idea of JOIN yet.
No comments:
Post a Comment