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,753
  • 72
  • 57
  • 129
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

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
  • 37,009
  • 9
  • 76
  • 105
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,242,037
  • 58
  • 646
  • 786