i have following two case-tables. tbl_emp is master table, say:-
----------------------------------------------------------
tbl_emp
----------------------------------------------------------
emp_id emp_name
1 Peter
2 Matt
3 Jacob
----------------------------------------------------------
and the detail table has the family details for employees.......
-----------------------------------------------------------------
tbl_family
----------------------------------------------------------------
family_id emp_id relation name age
-----------------------------------------------------------------
1 1 WIFE Susan 32
2 1 SON Jack 3
3 2 DAUGHTER Hannah 4
4 2 WIFE Leah 29
5 1 WIFE Anna 38
6 3 MOTHER Loran 73
7 2 MOTHER Sofia 81
------------------------------------------------------------------
I want a query to know who all employees have a specific 'relation' entry in the tbl_family and who DONT have. eg i managed following query for the employess having WIFE entry
select * from tbl_emp, tbl_family where
tbl_emp.emp_id = tbl_family.emp_id and
tbl_family.relation = 'WIFE'
this query returns Peter and Matt correctly. But i need queries for three issues. firstly. to give me employees with no WIFE entry in tbl_family. i.e the out put should be
---------------------------------------
emp_id emp_name
---------------------------------------
3 Jacob
---------------------------------------
seconldy, records with two WIFE entries (or any other relation) for the dataset it would give
-----------------------------------------
emp_id emp_name
-----------------------------------------
1 Peter
-----------------------------------------
and lastly, all those employees who have WIFE and MOTHER entries. Thise query would return
-----------------------------------------
emp_id emp_name
-----------------------------------------
2 Matt
-----------------------------------------
I have edited question with all result outputs. Thanks.