0
UPDATE `FlightSchedule`
SET delay=(
  SELECT *
  FROM (
    SELECT
      MINUTE(ETA - STA)
    FROM `FlightSchedule`
      WHERE `flightNum_arr` = '3517'
  )
)
WHERE `flightNum_arr` = '3517';

Says:

"Every derived table must have its own alias".

How to fix this issue?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Klausos Klausos
  • 14,142
  • 48
  • 129
  • 212

2 Answers2

3

Fixing it - exactly like it was shown in your error message:

UPDATE `FlightSchedule` 
SET delay=
(SELECT update_field
 FROM 
 (
  SELECT MINUTE (ETA - STA) AS update_field
  FROM `FlightSchedule` 
  WHERE `flightNum_arr`='3517'
 ) AS internal_0
)
WHERE `flightNum_arr`='3517';

But actually above there more correct suggestion - get rid of that nested subquery at all (see Gordon's answer).

Edit (based on comments):

If you want to find difference, use TIMEDIFF function:

UPDATE `FlightSchedule` 
    SET delay = TIMEDIFF(ETA - STA)
    WHERE `flightNum_arr`='3517';
Alma Do
  • 36,374
  • 9
  • 70
  • 101
3

The problem is in the nested subquery. But you don't even need it. The right way to write this query is:

UPDATE `FlightSchedule` 
    SET delay = MINUTE(ETA - STA)
    WHERE `flightNum_arr`='3517';
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709