-2

I am trying to get the speed where it is less than 10 from the group but I am getting this error:

How can I fix it?

Every derived table must have its own alias

mysql code:

SELECT speed from 
     (SELECT stop_distance
     FROM prognosis
     WHERE mac = '12:B4:B3:89:H3:I3'
     and stop_name = 'Sandstreet'
     and stop_distance < 61) 
 where speed < 10
benz
  • 693
  • 1
  • 9
  • 29
  • 2
    possible duplicate of [every derived table must have its own alias](http://stackoverflow.com/questions/1888779/every-derived-table-must-have-its-own-alias) – user4003407 Sep 08 '15 at 21:35
  • 1
    You need to give an alias to the subquery: `FROM (SELECT ...) AS distance`. – gen_Eric Sep 08 '15 at 21:36
  • 1
    After solving that error, there will be another. The inner query (which is the 'derived table' of the error message) doesn't return a column 'speed'. – GolezTrol Sep 08 '15 at 21:38

1 Answers1

2

Add an alias to identify your subselect:

SELECT speed from 
     (SELECT stop_distance
     FROM prognosis
     WHERE mac = '12:B4:B3:89:H3:I3'
     and stop_name = 'Sandstreet'
     and stop_distance < 61) AS sub_select
 where speed < 10

However I think you still have a problem. Your sub-select essentially acts like a temporary table* with a single column stop_distance. But you are trying to select speed from it. That won't work. You may need to do some research or ask a different question to get a query that will give you the desired result.

* I'm sure thats not technically correct

Dan
  • 10,614
  • 5
  • 24
  • 35