开发者

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:

开发者_如何学JAVA
INSERT 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")
                     )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜