New to SQL table binding

I'm new to SQL, so forgive me if I get it wrong.

I have one table called Employees, where I have columns for:

EmployeeID - This is Int Identity (1,1)
FirstName
LastName

I have a second table called Calendar, with calendar information populated over the next 50 years. Columns:

FullDate
Year
Month
Week
DayofWeek
DayofMonth
DayofYear
TypeofDay - (Weekday, Weekend, Bank holiday etc)

Now that I'm a little confused - it seems to me that I need a third table (Table 3), which links the two tables above, so I have a table with something like:

TableId
FullDate - linked from calendar table
EmployeeID - linked from employee table
FirstName - linked from employee table
LastName - linked from employee table
Shift1Text
Shift2Text

If my understanding is correct, I can use a command like:

select * from Table3 where FullDate = **Chosen Date / DateRange** 

so I get the output line by line:

Table ID | FullDate   | EmployeeID | FirstName | LastName | Shift1Text | Shift2Text 
---------+------------+------------+-----------+----------+------------+------------
1        | 22/06/2015 | 1          | Joe       | Blogs    | SomeText   | SomeText   
2        | 22/06/2015 | 2          | Fred      | Smith    | SomeText   | SomeText   
3        | 22/06/2015 | 3          | Bob       | Jones    | SomeText   | SomeText   
4        | 23/06/2015 | 1          | Joe       | Blogs    | SomeText   | SomeText   
5        | 23/06/2015 | 2          | Fred      | Smith    | SomeText   | SomeText   

etc.

The problem is that I have no idea how to link tables in this way or automatically fill the rows of the third table with information about the date and employee from the first two tables.

+4
3

ID Calender, - enter image description here

. EmployeeDate FirstName LastName, EmployeeID, Employee, .

.

Select * from Employee as E
  Join EmployeeDate as ED 
    on E.EmployeeID = ED.EmployeeID
  Join DateTable D 
    on D.Dateid = ED.Dateid
Where D.fulldate = <your full Date>

+2

, - . Calender, . , :

select c.fulldate, e.employeeid, e.firstname, e.lastname (other columns....)
from employees e
join calendar c on c.employeeid = e.employeeid

( my-sql ?)

0

enter image description here

I really don't understand what your calendar does on a calendar. But if you link two tables like tht, it means that one employee has one calendar. In the event that one employee has several calendars, you must remove the primary key from the Calendar. The main key means uniqueness. For an employee, this means that employees cannot use the same identifier.

I don’t understand what is the relationship between your employees and your calendar

0
source

All Articles