views:

37

answers:

2

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))
+2  A: 

Do it this way:

INSERT INTO  
    Html_Content (pageid, html_content)  
VALUES  
    SELECT 20, page_text FROM pages WHERE pageid = 29
Ray
+7  A: 

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.

Bob Palmer