Insert Query with Subquery
I'm trying to make an Insert query with a subquery. I have to insert other data apart from the subquery result. This is the query I have right now:
开发者_如何学JAVAINSERT INTO articles (title,content,frontpage,date_created,userID,catID,sectionID)
values("merijnmoetleren","blalblrsklfdkf", 1, "2010-01-23", 5, 2,
(SELECT id FROM sections WHERE name ="about")
What's wrong with it?
See if this works
INSERT INTO articles ( title, content, frontpage, date_created, userID, catID, sectionID ) SELECT "merijnmoetleren","blalblrsklfdkf", 1, "2010-01-23", 5, 2, id FROM sections WHERE name ="about"
Try this:
INSERT INTO articles
(title, content, frontpage, date_created, userID, catID, sectionID)
SELECT "merijnmoetleren", "blalblrsklfdkf", 1, "2010-01-23", 5, 2, id
FROM sections WHERE name = "about";
Put another closing paranthesis at the end.
INSERT INTO articles ( title
, content
, frontpage
, date_created
, userID
, catID
, sectionID
)
values ( "merijnmoetleren"
, "blalblrsklfdkf"
, 1
, "2010-01-23"
, 5
, 2
, (SELECT TOP 1 id FROM sections WHERE name ="about")
)
精彩评论