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
https://forums.phpfreaks.com/topic/66998-joinnormalize-help/
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
https://forums.phpfreaks.com/topic/66998-joinnormalize-help/#findComment-336130
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.