Selecting * from multiple tables

2001-08-27 Thread Dave Mittner


I'm running into a snag... here's an example of the query I'm making
from within Perl:

SELECT * FROM table1,table2

I know it's not a nice way to do it, but I'm making an SQL webpage
frontend which I'd like to support it just in case. I'm
using fetchrow-hashref to pull it out and display it. The problem I'm
running into is when table1 and table2 have similar
column names. One of them would be overwritten in the hash reference to
be replaced by the second one it encounters.

So my question is this. Is there any way to force MySQL to ouput the
table name with the column name instead of just the
column name, ie. table1.column2.

Thanks in advance,
Dave Mittner


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Selecting * from multiple tables

2001-08-27 Thread Paul DuBois

At 10:43 AM -0700 8/27/01, Dave Mittner wrote:
I'm running into a snag... here's an example of the query I'm making
from within Perl:

SELECT * FROM table1,table2

I know it's not a nice way to do it, but I'm making an SQL webpage
frontend which I'd like to support it just in case. I'm
using fetchrow-hashref to pull it out and display it. The problem I'm
running into is when table1 and table2 have similar
column names. One of them would be overwritten in the hash reference to
be replaced by the second one it encounters.

So my question is this. Is there any way to force MySQL to ouput the
table name with the column name instead of just the
column name, ie. table1.column2.

No.  Name the columns explicitly and give them aliases.


Thanks in advance,
Dave Mittner


-- 
Paul DuBois, [EMAIL PROTECTED]

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Selecting * from multiple tables

2001-08-27 Thread Ian Barwick

On Monday 27 August 2001 19:43, Dave Mittner wrote:
 I'm running into a snag... here's an example of the query I'm making
 from within Perl:

 SELECT * FROM table1,table2

 I know it's not a nice way to do it, but I'm making an SQL webpage
 frontend which I'd like to support it just in case. I'm
 using fetchrow-hashref to pull it out and display it. The problem I'm
 running into is when table1 and table2 have similar
 column names. One of them would be overwritten in the hash reference to
 be replaced by the second one it encounters.

 So my question is this. Is there any way to force MySQL to ouput the
 table name with the column name instead of just the
 column name, ie. table1.column2.

Not that I know of. What you could do is create aliases using AS, e.g.

  SELECT *, table2.column2 AS table2_column2 FROM table1,table2

but then you would need to know which columns to alias.

Or how about using fetchrow_arrayref()? That would remove the duplicate hash 
key problem, although you would have to extrapolate the column names yourself.

Hope your system has lots of memory to cope with that select statement on 
tables of any significant size ;-)

HTH

Ian Barwick

-- 
Ian Barwick - Developer - [EMAIL PROTECTED]
akademie.de asp GmbH - http://www.akademie.de

To query tables in a MySQL database is more fun than eating spam

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php