Reputation: 4281
I have a database query
SELECT Id FROM Phone WHERE Model = 'Droid'
that returns a table with one entry (because Id is a primary key). The table looks like this:
+----+
| Id |
+----+
| 1 |
+----+
Is there any way to get at that integer "1"? I'd like to use it in the following query, but it's generating a syntax error:
INSERT INTO Sale (Id, Price)
VALUES (SELECT Id FROM Phone WHERE Model = 'Droid', 100.00);
Upvotes: 0
Views: 51
Reputation: 7780
You simply need brackets around your select query like so:
INSERT INTO Sale (Id, Price)
VALUES ((SELECT Id FROM Phone WHERE Model = 'Droid'), 100.00);
That should work correctly.
Upvotes: 1
Reputation: 5216
It's not that you're getting some kind of type incompatibility; your syntax is just wrong. Try simply
INSERT INTO Sale (Id, Price)
(SELECT Id,100 FROM Phone WHERE Model = 'Droid');
Upvotes: 0
Reputation: 230561
Use this:
INSERT INTO Sale (Id, Price)
SELECT Id, 100.00
FROM Phone
WHERE Model = 'Droid';
Upvotes: 3