954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Copy table but with different IDs

hello,

I have a simple problem. I need to create a new table "smaller" using the data from an old table "larger" table. When I say smaller I mean it will have the exact structure as the older table but will have only a few records.

Now, i know that i can use:

CREATE TABLE new_table_name SELECT * FROM old_table_name WHERE id >= 1 AND id <= 5;"


but the problem is that i want to SELECT multiple sets of records. So in the example above I select WHERE id>= 1 AND id <=5 but say I also want to have id >= 10 AND id <=15 would I just do this:

CREATE TABLE new_table_name SELECT * FROM old_table_name WHERE (id >= 1 AND id <= 5) (id >= 10 AND id <= 15);"


I am using php. The usr decides what records are to be added into the new table and they are given multiple input text fields for each starting id and finishing id. I want to be able to do this with one query!

User input interface:
New Table Name : _______________
Starting ID : ___ , ___ , ___ , ___ , ___
Finishing ID : ___ , ___ , ___ , ___ , ___

Thanks for your help.

nika201
Newbie Poster
11 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

The only thing missing is an OR:

WHERE (id >= 1 AND id <= 5) OR (id >= 10 AND id <= 15)
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: