Link to home
Create AccountLog in
Avatar of brihol44
brihol44

asked on

I need help in getting data from one table to another...

I have the following example for data within a table...

COL A = ID        COL B  = Group         COL C = Company ID           COL D = Company Name     COL E = Zip
1                        A                                5                                          Company A                              97401
2                        B                                5                                          Company A                              97401
3                        C                                5                                          Company A                              97401
4                        A                               8                                          Company B                               97401
5                        B                               8                                          Company B                               97401

What I need to do is create two tables so I can break up the information more efficiently.

So....

Table company_link

COL A = ID    COL B  = Group   COL C = Company ID  
1                    A                         5
2                    B                         5
3                    C                         5
4                    A                        8
5                    B                        8


Table companies

COL A = Company ID   COL B = Company Name  COL C = Zip
5                                   Company A                       97401
8                                   Company B                       97401

I'm just not sure how to take the data from one table and do this using MySQL or Coldfusion.

Thanks,

Brian
 
Avatar of hielo
hielo
Flag of Wallis and Futuna image

This is basically what you need:
Insert INTO `company_link`(ID,Group,`Company ID`) SELECT ID, `Group`, `Company ID` FROM MasterTable

Insert INTO `companies`(ID,`Company Name`,Zip) SELECT ID, `Company Name`, Zip FROM MasterTable

More info here:
http://www.1keydata.com/sql/sqlinsert.html
What I understand that you are looking for a SELECT statement, if so then you are looking for the following:

Select * FROM company_link a, companies b WHERE a.company_id = b.company_id

the result should be your first table.
ASKER CERTIFIED SOLUTION
Avatar of ehabafia
ehabafia
Flag of Saudi Arabia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of brihol44
brihol44

ASKER

Yes, you are correct. I needed the distinct part. Thank you!
Sorry Hielo!  I meant to distribute the points evenly.