Jump to content


combine 2 tables


8 replies to this topic

#1 famer

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 11 November 2005 - 03:42 PM

mySQL
how combine 2 tables with equal structures?

#2 Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 11 November 2005 - 04:43 PM

what do you mean combine? you mean transfer the data from one table into another?

i dont know if there is a quicker way but i would just download a backup of the whole database and take the relevant section containing the info for the 2nd table and run the query on the 1st table.

#3 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 11 November 2005 - 05:48 PM

The more complicated automated way would be to run a loop taking out all the data from one table and during that loop, insert it into the other table with the nested fields.

#4 famer

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 12 November 2005 - 05:55 AM

I mean join, i just think that mysql have a command for it.
ok i'll do it with a script.
thanx

#5 saferwaters

    Jedi In Training

  • Members
  • PipPip
  • 390 posts

Posted 12 November 2005 - 08:06 AM

It does...its like:

SELECT * FROM table1, table2 WHERE table1.field = table2.field

Or so...and the table1.field MUST be the same as table2.field...such as most tables have an ID column.

#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 12 November 2005 - 08:16 AM

no the code u want is :

Quote

SELECT `colums` INTO `new_tbl_name` FROM `tables` WHERE `table1.id` = `table1.id`;


#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 November 2005 - 12:58 PM

If he wants to select stuff from multiple tables at once, then darth's code is right.
Since i don't know much about SELECT INTO, i can only assume that would select everything from `tables` and paste it into the `new_tbl_name`.

So depending on what needs to be done, you both may be correct. My simple suggestion would be to look at the following links, and then bookmark them.
http://dev.mysql.com...sql-syntax.html
http://www.w3schools.../sql_select.asp

#8 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 12 November 2005 - 01:21 PM

well darths is just selecting from tables. Farmer wanted to combine two tables, and u can select multiple tables with the SELECT INTO, then u just make the new table and then u can delete the others after.

#9 famer

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 12 November 2005 - 02:50 PM

great!
thanx ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users