Link to home
Start Free TrialLog in
Avatar of willsherwood
willsherwood

asked on

MySQL table alias names

why does the first example below work, and the second complains of unknown field Sort

SELECT...  
        FROM PropertyListings AS PL , Towns AS T, Counties AS C                              
      WHERE PL.TownshipID = T.ID AND PL.CountyID = C.ID
      ORDER BY T.Sort DESC                               <---  (1)  WORKS

        ORDER BY Towns.Sort DESC                               <---  (2)  FAILS


thanks
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so when the program encounters the t.fieldname it knows to take it from the town table
Avatar of willsherwood
willsherwood

ASKER

sorry my question was not clear lisa, i'm aware of the benefit of aliases,
but thanks angel, i did not know that defining/declaring an alias then deleted access for using the original table name.  I hear you, that just seems like an unreasonably strict language definition decision for MySQL.

thanks all
hi willsherwood

sorry should have explained better I meant it as when you declare anything as a name you must keep that name throughout so the program knows what field your are referencing

ie when it sees a t.whatever then it knows that its referencing the towns table
thanks.
i think the term "alias" is a misnomer  :)    

 (maybe a better term would be replacement or re-definition)
I know of the same problems in MS SQL and Oracle ...  so it's not just a MySQL "issue"
thanks (sorry i thought i had closed this, but alas i had not confirmed)