开发者

Why can I not express this subquery? Is there an alternative?

开发者 https://www.devze.com 2022-12-16 09:40 出处:网络
I get an error: Subqueries are not allowed in this context. Only scalar expressions are allowed. Why are subqueries not allowed? I\'m just trying to move 开发者_运维知识库some value over to anothe

I get an error:

Subqueries are not allowed in this context. Only scalar expressions are allowed.

Why are subqueries not allowed? I'm just trying to move 开发者_运维知识库some value over to another row in the same database. Is there another way of expression this quickly? (it's just a one-time operation...)

INSERT INTO 
    Html_Content (pageid, html_content) 
VALUES 
    (20, (SELECT page_text FROM pages WHERE pageid = 29))


Change your query to:

INSERT INTO  
    Html_Content (pageid, html_content)  
SELECT  
    20, page_text FROM pages WHERE pageid = 29

Reasoning is that this format is the one you would want to use whenever you need to drop the contents of a subquery into another table. You received the scalar error since by using the Values option, you're telling SQL you are inserting discreet values for each column, and only inserting a single row.


Do it this way:

INSERT INTO  
    Html_Content (pageid, html_content)  
VALUES  
    SELECT 20, page_text FROM pages WHERE pageid = 29
0

精彩评论

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

关注公众号