• David Walker-278941 (10/7/2009)


    Yet another article that makes people think that table aliases (t1 and t2) are part of the required syntax. This first Join statement:

    SELECT t1.key1, t1.field1 as Name, t1.key2 as T1Key,

    t2.key2 as T2Key, t2.field1 as City

    FROM Table1 t1

    INNER JOIN Table2 t2 ON t1.key2 = t2.key2

    Should be written like this:

    SELECT Table1.key1, Table1.field1 as Name, Table1.key2 as T1Key,

    Table2.key2 as T2Key, Table2.field1 as City

    FROM Table1

    INNER JOIN Table2 ON Table1.key2 = Table2.key2

    Isn't that easier to read?

    In this simple example, why in the WORLD are you including table aliases for Table1 and Table2? They are COMPLETELY unneccessary. When new users are exposed to table aliases in this kind of setting, they naturally think the table aliases are required.

    It gets more important when the tables are named ClientStatus and ClientOrders and people start aliasing them as "cs" and "co", or even worse, as "a" and "b".

    PLEASE don't teach that table aliases are a required part of the syntax. When they are required, they are required, but not in this simple example, and here they add nothing -- and they DETRACT from human readability -- in such simple examples. The human mind has to keep track of which alias goes with which table, and it gets hard when there are 5 or 6 tables involved.

    It's also good to see a <= join here. That's often left out of examples. Don't forget to also teach that you can join tables on two conditions (using AND/OR), not just one.

    Thanks.

    David Walker

    i have seen the same thing

    the rule is you write code to look cool, hardware is cheap