I am afraid that this is standard MySQL behaviour. The DBI will report whatever it gets from the DBD driver, and in this case MySQL does not report the table name.
mysql> describe test; +-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | title | char(10) | YES | | NULL | | +-------+----------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) mysql> select * from test; +----+--------+ | id | title | +----+--------+ | 1 | first | | 2 | second | +----+--------+ 2 rows in set (0.00 sec) mysql> select a.id, a.title, b.id, b.title from test a, test b where a +.id=b.id; +----+--------+----+--------+ | id | title | id | title | +----+--------+----+--------+ | 1 | first | 1 | first | | 2 | second | 2 | second | +----+--------+----+--------+ 2 rows in set (0.00 sec)
As you can see, querying from the normal MySQL client, the server is returning the same name for both fields. Thus, DBI will get only one of the two columns.
From DBI POD:
If more than one field has the same name, there will only be one entry in the returned hash for those fields.

However, if you ask esplicitly, you get the distinction.
I advise you to differenciate ambiguous names ALWAYS, no matter how smart the database driver seems to be .
mysql> select a.id as a_id, a.title as a_title, b.id as b_id, b.title +as b_title from test a inner join test2 b using(id); +------+---------+------+---------+ | a_id | a_title | b_id | b_title | +------+---------+------+---------+ | 1 | first | 1 | first | | 2 | second | 2 | second | +------+---------+------+---------+ 2 rows in set (0.00 sec)
_ _ _ _ (_|| | |(_|>< _|

In reply to Re: DBI table AND column names in fetchall_arrayref({})? by gmax
in thread DBI table AND column names in fetchall_arrayref({})? by kstephens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.