views:

17

answers:

1

I have a bunch of fields named the same across multiple tables (I inherited it - don't blame me ;).

Instead of setting up all of the aliases verbosely, is it possible to assign/prepend an alias automatically by way of a wildcard?

I'm envisioning something like (which of course doesn't really work):

SELECT t1.*,t2.* as alias2.*, t3.* as alias3.*

So I would get returned fields like:

name, address, city, state
alias2.name, alias2.address, alias2.city, alias2.state
alias3.name, alias3.address, alias3.city, alias3.state
+1  A: 

This does, if you use it as:

SELECT t1.*, alias2.*, alias3.*
  FROM t1, 
       t2 AS alias2, 
       t3 AS alias3

Define the table alias, then you can use the table alias.* in the SELECT. But it's still going to make getting the correct address/etc field a pain without a unique column alias...

Disclaimer

I only used ANSI-89 syntax for brevity - honest.

OMG Ponies
Right, my goal of course is to have unique column names as easily as possible. I guess the answer is that the unique column names must be aliased individually and by hand, yes?
k00k
@k00k: You are correct, sir.
OMG Ponies