Query
Posted: Sun Jul 06, 2008 1:07 pm
Hello,
I have the following tables and their fields in them
staff :- staff_id, staff_fname, staff_lname, staff_desig_id, staff_org_id
group:- group_id, group_name
division:- division_id, division_name
section:- section_id, section_name
staff_org:- staff_org_id, section_id, division_id, group_id
In the staff_org table,
If the section_id is empty and division_id is null and group_id is not null then the staff member belongs to whole group
If the section_id is empty and division_id is not null and group_id is not null then the staff member belongs to whole division
If the section_id is not null and division_id is not null and group_id is not null then the staff belongs to the indicated section
A staff who is a group director will belong to the whole group. So the first condition gets satisfied. To retrive his details i am using the below query,
$q = "SELECT CONCAT(staff_fname, staff_lname) AS staff_name FROM staff WHERE staff_org_id = 1";
I am checking staff_org_id with a static id which i think iam doing wrong thing. Can someone help in getting the above query correctly?
Thanks
I have the following tables and their fields in them
staff :- staff_id, staff_fname, staff_lname, staff_desig_id, staff_org_id
group:- group_id, group_name
division:- division_id, division_name
section:- section_id, section_name
staff_org:- staff_org_id, section_id, division_id, group_id
In the staff_org table,
If the section_id is empty and division_id is null and group_id is not null then the staff member belongs to whole group
If the section_id is empty and division_id is not null and group_id is not null then the staff member belongs to whole division
If the section_id is not null and division_id is not null and group_id is not null then the staff belongs to the indicated section
A staff who is a group director will belong to the whole group. So the first condition gets satisfied. To retrive his details i am using the below query,
$q = "SELECT CONCAT(staff_fname, staff_lname) AS staff_name FROM staff WHERE staff_org_id = 1";
I am checking staff_org_id with a static id which i think iam doing wrong thing. Can someone help in getting the above query correctly?
Thanks