Reputation: 5
I'm trying to INSERT new row with this values (hotelNo,guestNo,dataform,dataTo,roomNo) I know the hotel name , so I have to SELECT the hotelNo from another table , it didn't work with me , is there something wrong?
INSERT INTO Booking
VALUES (hotelNo,123,'3-sept-1014','3-sept-1014',121)
(SELECT hotelNo
FROM Hotel
WHERE hotelName='Ritz Carlton' AND city='Dubai');
Upvotes: 0
Views: 215
Reputation: 18767
Remove VALUES (hotelNo,...
from your query and you are good to go.
INSERT INTO Booking
(SELECT hotelNo,123,'3-sept-1014','3-sept-1014',121
FROM Hotel
WHERE hotelName='Ritz Carlton' AND city='Dubai')
Upvotes: 5
Reputation: 53
Try this:
INSERT INTO Booking VALUES (
(SELECT hotelNo
FROM Hotel
WHERE hotelName='Ritz Carlton' AND city='Dubai'),
123,'3-sept-1014','3-sept-1014',121);
Upvotes: 1
Reputation: 989
You should do it without VALUES
INSERT INTO Booking
(SELECT hotelNo, 123, '3-sept-1014','3-sept-1014',121
FROM Hotel
WHERE hotelName='Ritz Carlton' AND city='Dubai');
Upvotes: 3