Jump to content


Photo

help with connecting two tables


  • Please log in to reply
4 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 10 April 2006 - 04:00 PM

Hey....

I have

table 1
---------------------

field - letter

and have 26 records for this

then i have

table 2
--------------------

fields - table2_id and table2_letter

and 26 records for this.

what i want to do is select a letter from table 1 and put it in field table2_letter but not duplicate it

any ideas please?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 10 April 2006 - 06:49 PM

As you have 26 recs in table2, adding a 27th without duplication could be difficult.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 11 April 2006 - 02:36 PM

sorry i dont think u understood,

what i want to do is take the 26 records from the one table and enter them into the a field in the other table without any duplicates?

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 11 April 2006 - 08:23 PM

If you want them in the same sequence

INSERT INTO table2 (letter) SELECT letter FROM table1

If you want them in a random sequence

INSERT INTO table2 (letter) SELECT letter FROM table1 ORDER BY RAND()

This assumes table2.id is auto_increment column.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 April 2006 - 07:30 AM

Thanks that inserts them, but what happens if i already have the records in the table and want to update them?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users