开发者

MySQL: Possible to have wildcards in AS aliases?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜