List:General Discussion« Previous MessageNext Message »
From:David Lerer Date:August 3 2011 2:24pm
Subject:RE: Too many aliases
View as plain text  
I rarely use aliases (unless rarely required in self-join queries).
When I have that option, I create unique columns by prefixing every
table (and its objects) with a number.
Something like:
Create table T1234_Employee
  (C1234_Employee_id number(5),
   C1234_employee_status char(1)...)
  Index X1234_Employee_Id on .... Etc.

Yes, the column names may be longer this way, but easy to refer to and
easy to communicate (by specifying a table number). I wonder what others
think about it.

David.

-----Original Message-----
From: Rik Wasmus [mailto:rik@stripped] 
Sent: Wednesday, August 03, 2011 6:47 AM
To: mysql@stripped
Subject: Re: Too many aliases

> >>>> 2011/08/02 12:11 +0530, Adarsh Sharma >>>>
> 
> select p.* from table A p, B q where p.id=q.id
> 
> or
> 
> select p.* from table B q , A p where q.id=p.id
> <<<<<<<<
> Why do people constantly change table names for queries, although, as
here,
> it gain them nothing? It often makes for less clarity (for which table
is
> this an alias???).

Depens on your table names. I rather like being able to give a short 
description rather then long table names if someone decided that as a 
tablename. I doubt your example with already short tablenames is one
from real 
life, but if you saw someone doing it would indeed be a waste of time.
But the 
main thing is it helps to distinguish tables  in joins having the same
table 
more then once (and of course results from subqueries etc.):

SELECT first.* 
FROM tablename first
LEFT JOIN   tablename second
   ON    first.some_id = second.some_id
   AND first.id != second.id
WHERE second.id IS NULL
-- 
Rik Wasmus

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=1

Thread
Which is betterAdarsh Sharma2 Aug
  • RE: Which is betterShafi AHMED2 Aug
  • Too many aliaseshsv2 Aug
    • Re: Too many aliasesRik Wasmus3 Aug
      • RE: Too many aliasesDavid Lerer3 Aug
        • RE: Too many aliasesshawn wilson3 Aug
        • RE: Too many aliasesJerry Schwartz4 Aug
      • Re: Too many aliaseshsv4 Aug
        • RE: Too many aliasesDavid Lerer4 Aug
          • Re: Too many aliasesMike Diehl4 Aug
            • Re: Too many aliasesJohnny Withers4 Aug
              • Re: Too many aliaseshsv6 Aug
                • Re: Too many aliasesJohnny Withers7 Aug
  • Re: Which is betterMySQL)2 Aug
    • RE: Which is betterDavid Lerer2 Aug
Re: Which is betterPrabhat Kumar2 Aug