tags:

views:

72

answers:

1

Hi,

I've the following query:

INSERT INTO 
                                table
                            (
                                memberid,
                                field1,
                                field2,
                                field3
                            )  
                            VALUES
                            (
                                :memberid,              
                                (
                                    SELECT
                                        field1,
                                        field2,
                                        field3
                                    FROM 
                                        table
                                    WHERE 
                                        id = :id
                                )
                            )

I'm using PDO prepared statements, but the query doesn't work in this way.

Does anyone know how to combine prepared statements and SELECT variables into one query?

Tnx

+3  A: 

Have you considered insert-select?

INSERT INTO mytable (a,b) 
SELECT :a, b
FROM myothertable
Victor Nicollet
I've tried that, but that isn't working. I get this error:Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 in
Arjen
You're probably using code like "INSERT INTO (a,b,c) SELECT a,b". Post the actual query and we'll count the columns and values for you.
Victor Nicollet
Thank you. I made a mistake with setting the VALUES parameter (thanks Gumbo)
Arjen