Jump to content

Select then Insert into another table


CBG

Recommended Posts

Hi,

 

I would like to do the following in PHP using a MySQL database, but not sure how.

 

select a, b,c etc.. from mailbox where id = X

then

insert id,a,b,c etc.. into problem

 

When I select, I will be calling the id

 

So I would like it to get data from mailbox and then insert it into problem.

How would I go about doing this?

 

Thanks for any help you can give me :)

Link to comment
Share on other sites

Try having a read about subqueries or derived tables as they are sometimes know.

 

Something like this should work


INSERT INTO tblTABLE SET (Field1, Field2)
VALUES (SELECT Field1, Field2 FROM tblTABLE2)

 

It's a very simplified example but the logic should work.

Link to comment
Share on other sites

Just thought I would come back with a follow up on this.

It working fine. I didn't put SET in it, as I thought that was for update.

 

But anyway it works great.

Thank you very much 8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.