Jump to content

Join/normalize help!


gigantorTRON

Recommended Posts

Hey guys! I'm a semi n00bie here and I am having a really hard time with this new project. What I'm needing to do is create a new table that pulls data in from existing legacy system tables. For example...

 

I'm making a table like this one..

| InventoryID | InventoryDesc | InventoryType

 

The data to populate this table has to come from other tables which are arranged in a hierarchical fashion. I can select InventoryID straight in from Table A. To get the inventory description though, I have to get an inventoryDescription ID from Table A and then use that to reference the description field of table B and UPDATE my table. Finally, to get an inventoryType I have to get the inventory description ID from table A, pull the inventoryType ID from table B and then use that result to pull the inventoryType text from table C to UPDATE the table. So it all looks something like this... * is columns I need to pull in.

 

Table C:        InventoryTypeID      InventoryTypeDescr.*      InventoryTypeCount

 

Table B:      InventoryDescID      InventoryDescText*      InventoryTypeID

 

Table A:        InventoryID*      InventoryDescID    InventoryCount

 

Destination Table:      InventoryID      InventoryDescText      InventoryTypeDescr

 

I'm sure that this requires some sort of join which unfortunately I'm not too great with.

 

Any help??  ???

Link to comment
Share on other sites

Try this:

 

insert into destinationTable ( InventoryID, InventoryDescText, InventoryTypeDescr )
select a.inventoryID, b.InventoryDescText, c.InventoryTypeDescr
from tableA as a
join tableB as b on ( a.InventoryDescID = b.InventoryDescID )
join tableC as c on ( c.InventoryTypeID = b.InventoryTypeID )

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.