Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database week1/jianxin #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

database week1/jianxin #148

wants to merge 2 commits into from

Conversation

jianxinz233
Copy link
Collaborator

database week1 homework

Copy link

@josejfernandez josejfernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Jianxin, very well done! All your queries worked fine for me. I have written two comments with suggestions, that don't block the review. I still suggest that you address them, but it's up to you :)


-- Find all the tasks that are marked as done
SELECT * FROM task
WHERE status_id IN (SELECT id FROM status WHERE name LIKE "%done%");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not block the review because your query works, but I still suggest you follow this advice to get more clear and meaningful code.

You use IN when there is a list of possible values. Although it works in this case, there is only one status for "Done", so you could do SELECT * FROM task WHERE status_id = (...) and this statement would be a bit more clear.

Similarly, in the subquery you are searching for statuses whose name contain done. There is only one status for "Done", so you could do SELECT id FROM status WHERe name = 'Done', which again is a bit more clear.

-- Get the title and status (as text) of all tasks
SELECT task.title AS task_title, status.name AS task_status
FROM task
LEFT JOIN status on task.status_id = status.id;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The column status_id in the table task cannot be null (this can be checked in the CREATE TABLE statement here). This means that this LEFT JOIN is no different from an INNER JOIN or JOIN (which is the same as an INNER JOIN).

This doesn't block the review either, but I suggest that you use LEFT or RIGHT joins only when they make a difference from an INNER, i.e.: when the column you are joining on can be null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants