0

Is it 'SQL standard save' to use table alias names which do equal their table names?

Example:

I have a table aaa:

id
--
1
2
3

In MYSQL I run a query:

 select aaa.* from aaa aaa,aaa bbb

which results in:

id
--
1
2
3
1
2
3
1
2
3

So it seems, that MYSQL sort of prioritizes alias referencing over table referencing, which I like. However as I saw lots of 'random' programming out there I am not sure, if this is by purpose or by accident. So would I get any kind of error in Oracle SQL, MS SQL,... for the same setup? Or is exactly that piece of MYSQL behaviour reasoned in any SQL standardization specification?

Btw. I know the example is stupid and the question seems to be stupid. It is not. Imagine one would like to implement a database centric framework which could simplify its aliasing rules by defining: Each table has a default alias which equals the table name.

Quicker
  • 1,247
  • 8
  • 16
  • 1
    This is by purpose. Compare it to: `SELECT aaa.* FROM aaa bbb;` => it will give you an error. An aliased table will NOT be addressed by its actual name, ever. I can guarantee you this works like that in MySQL and PostgreSQL, I cannot vouch for Oracle or MS. – Wrikken Mar 13 '14 at 21:32
  • I was always under the assumption that your statement would work. But you are right it does not. Wow. I guess, I have to rethink some things. – Quicker Mar 13 '14 at 21:53

0 Answers0