SQL query : Insert DIFFERENCE OF TIME from different tables to a different table
INSERT INTO order_time( link, time )
SELECT link, CAST
(
( 
(
   SELECT FIRST (t.time AS dtime)
   FROM delivery_time t, quantity q
   WHERE t.link = q.link
) - 
(
    SELECT FIRST (orderTime)
    FROM delivery_time t, menu m, quantity q
    WHERE t.link = q.link
    AND t.menuId = m.menuId
)
) AS time( 0 )
)
FROM quantity where 1


m getting error message, plz help.

quantity comprises of (link,qty); link is unique and int

order_time: (link,time) ; link is unique and int, time is of datatype time

delivery_time: (link,menuId,time); for a menuId(int), there are different time (datatype time) and for a set of some different time for a menuId there is link; so menuId & time combination is unique:

menuId    time    link
1       12:00:00   1
1       12:10:00   1
1       14:00:00   2
1       14:10:00   2
1       14:20:00   2
2       12:00:00   3
2       12:10:00   3
2       12:20:00   3
2       14:00:00   4
2       14:10:00   4
2       15:00:00   5

& menu: (menuId, orderTime); menuId is unique & orderTime is in datatype time.

My need is: creating a table order_time (link,time) where link is unique & taken from quantity. here time is the difference of first instance of time corresponding to that link in delivery_time & orderTime from menu table that corresponds to menuId as in delivery_time table.

ERROR:MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(t.time AS dtime)
   FROM delivery_time t, quantity q
   WHERE t.link = q.link' at line 6 

SQL query : Insert DIFFERENCE OF TIME from different tables to a different table
===

INSERT INTO order_time( link, time )
SELECT link, CAST
(
( 
(
   SELECT FIRST (t.time AS dtime)
   FROM delivery_time t, quantity q
   WHERE t.link = q.link
) - 
(
    SELECT FIRST (orderTime)
    FROM delivery_time t, menu m, quantity q
    WHERE t.link = q.link
    AND t.menuId = m.menuId
)
) AS time( 0 )
)
FROM quantity where 1


m getting error message, plz help.

quantity comprises of (link,qty); link is unique and int

order_time: (link,time) ; link is unique and int, time is of datatype time

delivery_time: (link,menuId,time); for a menuId(int), there are different time (datatype time) and for a set of some different time for a menuId there is link; so menuId & time combination is unique:

menuId    time    link
1       12:00:00   1
1       12:10:00   1
1       14:00:00   2
1       14:10:00   2
1       14:20:00   2
2       12:00:00   3
2       12:10:00   3
2       12:20:00   3
2       14:00:00   4
2       14:10:00   4
2       15:00:00   5

& menu: (menuId, orderTime); menuId is unique & orderTime is in datatype time.

My need is: creating a table order_time (link,time) where link is unique & taken from quantity. here time is the difference of first instance of time corresponding to that link in delivery_time & orderTime from menu table that corresponds to menuId as in delivery_time table.

ERROR:MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(t.time AS dtime)
   FROM delivery_time t, quantity q
   WHERE t.link = q.link' at line 6 
