Jump to content

Insert from 1 table to 2 tables


nagrap

Recommended Posts

Hi,

 

I'm quite new to php and not the greatest of coders, so urgently require your help.

 

I want to be able to take data from an un-normalised table and load into 2 normalised tables as below:

 

1) Table 1 - All Music Tracks (Un-normalised table)

 

Album Name

Artist Name

Track Name

Track Length

etc.

 

2) Table 2 - Albums Table (Normalised table)

 

ID

Artist Name

Album Name

etc.

 

3) Table 3 - Tracks Table (Normalised table)

 

ID

Track Name

Album ID (foreign key to Albums table)

etc.

 

Can someone please provide some sample code as a starting point? The All Music Tracks table includes both the album name and track name in each row, but I only want the album appearing once in the Albums tables, would I have to do an Distinct select first to get the album names into an array? I'm not sure how I would then have  nested loop to do the insert into the Tracks table.

 

Much Appreciated,

 

PD

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.