Skip to content

Conversation

@aaronev
Copy link
Owner

@aaronev aaronev commented Mar 13, 2017

No description provided.

SELECT
name
FROM
student.student
Copy link

@ghost ghost Mar 13, 2017

Choose a reason for hiding this comment

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

This part looks fine, just wanted to comment that often in industry people would alias their tables here. E.g. "student.student s" would alias the table "s"

FROM
student.student
JOIN
student.friend
Copy link

Choose a reason for hiding this comment

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

This could be aliased too (for example f, or t2)

JOIN
student.friend
ON
student.student.id = student.friend.id1
Copy link

Choose a reason for hiding this comment

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

And here you could go s.id = f.id1

FROM
student
AS
student1
Copy link

@ghost ghost Mar 13, 2017

Choose a reason for hiding this comment

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

This is fine! Just a comment - It's okay to make short aliases, like s1, or s2, etc. to make typing easier.

@@ -0,0 +1,16 @@
INSERT INTO student VALUES (1510, 'Jordan', 9);
Copy link

Choose a reason for hiding this comment

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

This is a workaround from loading the CSV file directly. Different database systems have different ways of doing this (copy, load data infile), but it'll be good for you to learn the methods because sometimes you'll end up having to work with big files, or you will be automating things and so you won't want to write the code by hand.

ON
student.student.id = student.friend.id1
WHERE
id2 = 1911
Copy link

Choose a reason for hiding this comment

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

The spirit of this task is to query everyone who is friends with someone named Gabriel, so you would probably want the where clause to be on the name. Hardcoding it for the two student IDs of people named Gabriel is manual (so it's actually more work), and your query doesn't reflect the spirit of the question, and it will break if there are any new people named Gabriel. Ideally, someone would be able to tell what you're trying to do by reading your query.

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.

1 participant