I have a database with table named ‘Customers’ which it contains customer’s phone number. Its definitely more than one row.
On the other hand, I also have database named ‘SMS’ with a table in it, called ‘Outbox’.
In order to show all phone number from ‘Customers’ table, I use this SQL query:
SELECT Customers.PhoneNumber FROM Customers WHERE PurchaseDate BETWEEN 2012-01-01 AND 2012-01-31;
Now, I need those phone numbers (multiple rows) to be inserted into ‘Outbox’ at once. Every phone number will receive same message. So, basically I just need to know how to use this INSERT query for multiple rows:
INSERT INTO Outbox (PhoneNumber, Message) VALUES (*Multiple PhoneNumbers Here*, 'Same Message To All Customers');
I assume you want a separate row for each phone number. You can do this by combining INSERT with SELECT: