954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

query 3 tables to retrieve fields value and display table in a page

hi..

Im new to mysql..i want to know how to generate daily reports for all employees

i created 3 tables with fields

employee table:emp_id,name
job table:job_id,job_name
activity table:act_id,emp_name,job_name,date,activity done(assigned values as email,phonecall,visits)

Daily Activity Report : (Employee ID, Emp Name,Jobs Name, Activity Done)
Eg: 1.| Date | Rajeev | Income Tax Filing | Phone Call
Options to Select : 1. Which Date (Required - Not Null) 2. Employee Name,
if Employee Name not selected, then the list of Activities for that day for all Employees.

How to write query

danielbala
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

job_name in table activity should be job_id.

select * from employee e, job j, activity a 
where e.emp_id = a.emp_id and j.job_id = a.job_id and a.date = <selected_date>
/* optional: */ and e.name = <selected_name>


But you will never learn anything from the homework of others.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

Thanks for this I came here looking for the same thing.. Thought I would have to do a bunch of joins but this worked perfect.

reco21
Light Poster
33 posts since Jan 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: