0

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');
BSMN
  • 5
  • 1
  • 4
  • possible duplicate of [SQL Insert into ... values ( SELECT ... FROM ... )](http://stackoverflow.com/questions/25969/sql-insert-into-values-select-from) – Unix von Bash Apr 03 '14 at 17:57

3 Answers3

5

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')
Raging Bull
  • 18,593
  • 13
  • 50
  • 55
3

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');
Jerko W. Tisler
  • 996
  • 9
  • 29
1

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);
Andrew
  • 53
  • 6