문제

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
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top