0
select a as average,name 
from (select avg(marks) as a,name 
      from marks,student where rollno=roll group by marks.roll);

ERROR 1248 (42000): Every derived table must have its own alias

I know the correction. Just want to know why I have to use the alias?

select a as average,name 
from (select avg(marks) as a,name 
      from marks,student where rollno=roll group by marks.roll)xxx;
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Even if it was allowed, it would be sloppy to not name your objects. Be explicit in your code, especially with MySQL which will guess at stuff it shouldn't (I'm looking at you, missing-GROUP-BY clause). – JNevill Aug 20 '15 at 15:40
  • I think this is just a quirk of MySQL. – Barmar Aug 20 '15 at 15:43

2 Answers2

1

It's just a quirk in the design of MySQL. Oracle and SQL-Server don't require the alias in this case.

Barmar
  • 741,623
  • 53
  • 500
  • 612
0

If you want to select, you need to declare a From-clause. If there is not one, like in subselects, you are not able to even select. thats why SQL syntax defines to make a alias for each subselected table.

inetphantom
  • 2,498
  • 4
  • 38
  • 61