79158050

Date: 2024-11-05 07:38:17
Score: 0.5
Natty:
Report link

You can insert multiple rows into a table after ensuring that the table is empty by

INSERT INTO Persons
SELECT personID, personName
FROM (
  SELECT 1 as personID, "Jhon" as personName
  UNION ALL
  SELECT 2 as personID, "Steve" as personName
)
WHERE NOT EXISTS (SELECT 1 from Persons);

Where the "UNION ALL" statement is used to combine the result sets of two or more "SELECT" statement

Note: Forpas wrote the solution core here but I edited the syntax to insert multiple rows instead of one

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Abdulkerim Awad