sql-ecology-lesson icon indicating copy to clipboard operation
sql-ecology-lesson copied to clipboard

Small comments aliasing (03-sql-joins)

Open MathildeMousset opened this issue 6 years ago • 1 comments

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.

MathildeMousset avatar Apr 30 '19 12:04 MathildeMousset

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).

Discussion question: is it better to include the full table names (clearer, but longer) or alias them (shorter, but harder to read)?

ChristinaLK avatar Aug 12 '20 02:08 ChristinaLK