sql-ecology-lesson
sql-ecology-lesson copied to clipboard
Small comments aliasing (03-sql-joins)
I was confused by the example on aliasing at the end of 03-sql-joins.
I don't think that changing all by-now remembered tables and field names is making the query clearer, just shorter. It is, however, harder to read, as one has now to concentrate extra hard to learn the new names. Why renaming the tables?
I would simplify the example as below:
SELECT
surveys.year AS year,
surveys.month AS month,
surveys.day AS day,
species.genus AS genus,
species.species AS species
FROM surveys
JOIN species
ON surveys.species_id = species.species_id;
Additionaly, I did not wanted to create an issue, just for that, but maybe it would be good to introduce aliasing much before it is done, so that learners are exposed to it, and can use it in examples and challenges of all episodes.
Thanks for this observation @MathildeMousset. I think the reason to alias the tables is as you've mentioned - to make the query shorter - because otherwise it takes FOREVER to type. However, the speed comes at the cost of clarity! I think it would be worth hearing from people who have taught the lesson about the trade-offs.
(We do introduce aliases in a previous episode, so this is not the first time they appear, but we could maybe use them in more exercises so that people are familiar with them).