Jump to content


Photo

Inserting data from two places into a single table


  • Please log in to reply
3 replies to this topic

#1 VTS

VTS
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationTennessee

Posted 07 August 2006 - 03:30 PM

I will try to lay this out the best that I can.  I have a table that has the date, sales, department id, operating hours, and operating wages. 

I am getting the date, sales and department id from one place and then I am getting the operating hours and operating wages from another department. 

The major problem that I am having is that the place where I am getting the hours and wages from has some departements that the sales won't have and then the sales will have some departments that the hours and wages wont....does this mean I just need to make another table to store sales in one and wages and hours in another?

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 August 2006 - 03:35 PM

I am not sure what you mean, but could something like
SELECT * FROM table1 AS t1 LEFT JOIN table2 AS t2 ON t1.department_id=t2.department_id
do it?

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 07 August 2006 - 04:22 PM

I think he means he needs to 'INSERT' data from multiple sources. Is that correct?  ???

#4 VTS

VTS
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationTennessee

Posted 07 August 2006 - 04:46 PM

Well the problem was that one source will have wage data and the other source will have sales data and they will not always have the same departments.  For example, the wage data my contain departments 1, 2, 3, 4, and 5 while the sales data may contain departments 1, 2, 3, 6, and 7.  I was wondering how to go about inserting these into the datebase but I figured it out now.  I just made a new table containing all the the departments and their id numbers.  Then I used some sql and php to check and see what totals were missing and then if a total was missing, I just inserted zeroes into that row in the db.  After doing this, all of my departments were accounted for and then I could just use a simple update statement to put the sales data in.  Thanks for the posts guys!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users