Skip to content
Advertisement

How to add to INSERT INTO PRIMARY KEY AND FOREIGN KEY

So i have two tables: locations and employees i want locations_id to be the same in employees.locations_id, I am trying to make it all in one statement the erros is this 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 ‘INSERT INTO employees(employees_id, locations_id) VALUES(‘e1598′,”)’ at line 1

Advertisement

Answer

You should be using an INSERT INTO ... SELECT here:

To the ? placeholder you would bind a value from your Java code. Note that while your version of SQL might support putting a scalar subquery into a VALUES clause, it is likely that your exact version would cause an error, as it would return more than one row.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement