This is what I would do

Originally Posted by
Warlock
I have 2 tables one with one entry and one with 52 entries (weeks of the year). I need one Table. I have tried to use clone rows and then merge them together but this seems not to work.
ANy suggestions where to look ??
Ok, I have done this and I got the data. Now I want to put them together in one table. How ? See my last question.....
Thanks in advance....
This is what I would do: keep the two tables separate! It is an order of normalization of the database which will save storage space and, most importantly, prevent you from having to duplicate the employee's name in every record. The tables can then be joined with a query at runtime.
The first table would have two columns:
PK EmployeeID INT
EmployeeName TINYTEXT
and the second table would reference the employee by ID and contain the columns for the week data for each year:
PK EmployeeID INT
PK YearNumber INT
PK WeekNumber INT
MondayHours DECIMAL(10,1) [you could use negative numbers to flag the F, V, A conditions]
TuesdayHours DECIMAL(10,1)
... (for the rest of the days of the week)
Also, the EmployeeID in the second table MUST be declared as a foreign key that references the EmployeeID of the first table. That will keep the two tables in sync (referential integrity). You should set the foreign key to 'Cascade On Delete' so if an employee name is deleted, their entire calendar will be deleted as well. No orphans, please.
When you want to retrieve the data for a particular person for a particular year, you can join the two tables into one table with a SQL Join query:
SELECT * FROM table_1 t1
JOIN table_2 t2 USING (EmployeeID)
WHERE EmployeeName = ? AND YearNumber = ?
ORDER BY WeekNumber;
Last edited by darrell.nelson; 01-19-2010 at 07:42 PM.
pdi-ce-3.2.0-stable
bi-server-3.5.0.stable
MySQL 5.1
Windows XP