I have 3 tables as shown below
table 1
________________________________________________
id | effective_date | table_3_id | acc_name |
___|____________________|____________|__________|
112|2012-02-01 12:00:00 | 23 | Over Pay |
___|____________________|____________|__________|
table 2
__________________________________
id | table_1_id | amount |
______|________________|_________|
1 | 112 | 400.00 |
______|________________|_________|
table 3
________________________________________
id | emp_num | first_name | last_name|
____|__________|_____________|__________|
23 | 100004 | John | Doe |
____|__________|_____________|__________|
I have a start date and an end date and also a predefined value for acc_name. What I want to do is, to retrieve the emp_num, first_name, last_name and amount from relevant tables that have a effective_date that falls between start date and end date and also the acc_name should be the predefined value.
For above tables if my start date = 2012-01-30 12:00:00 , end date = 2012-03-01 12:00:00 and acc_name = Over Pay; then below values should be returned.
emp_num = 100004
first_name = John
last_name = Doe
amount = 400.00
How can I do this? I am not sure whether joining all 3 the tables is the best approach here. Can anyone help?
Yes. Use a join.
There is no 30th of February.