Arjen
Arjen

Reputation: 193

Combine php variable and SELECT variables into one SQL Insert query

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

Upvotes: 1

Views: 831

Answers (1)

Victor Nicollet
Victor Nicollet

Reputation: 24577

Have you considered insert-select?

INSERT INTO mytable (a,b) 
SELECT :a, b
FROM myothertable

Upvotes: 3

Related Questions