0

I have two tables;

  1. route_info: (routeinfo_id(primary key),route_src,route_dest,driver_id(foreign key)

  2. route_details: (routedetails_id (primary key), route_latitude,route_longitude,route_address, routeinfo_id (foreign key)).

I am facing an error while trying to insert data into route_details table by checking some constraint of route_info table.

My query:

INSERT INTO route_details (route_latitude,route_longitude,routeinfo_id) VALUES (78.23,27.54,1) 
SELECT * 
FROM route_details
WHERE route_address='CNG Station,Agartala' 
AND routeinfo_id IN (SELECT routeinfo_id 
                     FROM  route_info 
                      WHERE route_info.route_source='Udaipur' 
                        AND route_info.route_destination='Agartala' 
                        and route_info.driver_id=1);
  • And what is the error? –  Apr 15 '19 at 15:42
  • Erhm, AFAIK you cannot combine `VALUES (...)` and `SELECT ...` in the same `INSERT`. Try with `INSERT ... SELECT 78.23, 27.54, 1 FROM route_details WHERE EXISTS (...)` instead. – Ancoron Apr 15 '19 at 20:24

0 Answers0