Hi there!
I have a scenario where I am selecting from 2 tables:
tbl_name and tbl_matched
tbl_name has 2 columns: ID and NAME
tbl_matched has 2 columns: ID and STATUS
I would like to: "within one go" return the results of: ID, NAME, MATCHED, REJECTED
The MATCHED and REJECTED will be determined by the value of the STATUS column which can either hold a 'C' for matched and a 'R' for Rejected.
My query below returns the same amount of R's than it does C's ... when there are many more C's than R's.
select
a.id "ID",
a.name "NAME",
count(b.status) "MATCHED",
count(c.status) "REJECTED"
from tbl_name a,
tbl_matched b,
tbl_matched c
where
(a.id=b.id AND b.status = 'C') OR (a.id=c.id AND c.status = 'R')
group by a.id, a.name;
If anyone has any advice then that would be greatly appreciated! Thx S
I have a scenario where I am selecting from 2 tables:
tbl_name and tbl_matched
tbl_name has 2 columns: ID and NAME
tbl_matched has 2 columns: ID and STATUS
I would like to: "within one go" return the results of: ID, NAME, MATCHED, REJECTED
The MATCHED and REJECTED will be determined by the value of the STATUS column which can either hold a 'C' for matched and a 'R' for Rejected.
My query below returns the same amount of R's than it does C's ... when there are many more C's than R's.
select
a.id "ID",
a.name "NAME",
count(b.status) "MATCHED",
count(c.status) "REJECTED"
from tbl_name a,
tbl_matched b,
tbl_matched c
where
(a.id=b.id AND b.status = 'C') OR (a.id=c.id AND c.status = 'R')
group by a.id, a.name;
If anyone has any advice then that would be greatly appreciated! Thx S