Question

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?

Was it helpful?

Solution

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';

OTHER TIPS

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';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top