0
INSERT INTO `users`(`f_name`, `l_name`, `mobile`) VALUES (firstname, lastname, 8877665544);
INSERT INTO `dept`(`deptname`, `usercount`) VALUES (deptnmae, 32);

how can I add both table values in single query at the same time in php mysql

Premlatha
  • 1,676
  • 2
  • 20
  • 40
SanthoshKumar R
  • 111
  • 1
  • 2
  • 7
  • 5
    It's not possible. You can only insert into one table at a time. – Barmar Jan 28 '20 at 01:41
  • 5
    Use a transaction to make the two inserts atomic. – Barmar Jan 28 '20 at 01:43
  • Inserting both at the same time doesn't create a sensible relationship between the two entries, btw. – mario Jan 28 '20 at 01:46
  • Does this answer your question? [Insert into multiple tables in one query](https://stackoverflow.com/questions/3860280/sql-insert-into-multiple-tables-in-one-query) or [Insert into multiple tables](https://stackoverflow.com/questions/5178697/mysql-insert-into-multiple-tables-database-normalization). – showdev Jan 28 '20 at 03:00
  • You can do a transactional query but otherwise, you cannot insert it to two tables. – J.George Jan 28 '20 at 11:00

0 Answers0