leveetated
Programmer
Hello all,
I have a simple query that is just about to drive me nutty. I simply want to select the records in 1 table where the occurrence of a field value is limited to once.
This query does NOT work - and I don't know why. It returns all the rows where Ranking isn't only 0 (ranking = 0, ranking =1, ranking =2, etc.).
select id
from tbl1
inner join tbl2 on tbl2.objid=tbl1.id
where tbl1.ranking=0
and tbl1.tableid=108
and tbl2.classid=12
group by id
having count(*) = 1
order by id
The field value for id in this join should appear only once in tbl1, where ranking=0. I don't want records in tbl1 where the id (which is joined to tbl2.objid) value occurs more than once.
I hope I'm explaining this clearly, and I know this is a simple one. Any ideas, SQL experts?
Many thanks.
I have a simple query that is just about to drive me nutty. I simply want to select the records in 1 table where the occurrence of a field value is limited to once.
This query does NOT work - and I don't know why. It returns all the rows where Ranking isn't only 0 (ranking = 0, ranking =1, ranking =2, etc.).
select id
from tbl1
inner join tbl2 on tbl2.objid=tbl1.id
where tbl1.ranking=0
and tbl1.tableid=108
and tbl2.classid=12
group by id
having count(*) = 1
order by id
The field value for id in this join should appear only once in tbl1, where ranking=0. I don't want records in tbl1 where the id (which is joined to tbl2.objid) value occurs more than once.
I hope I'm explaining this clearly, and I know this is a simple one. Any ideas, SQL experts?
Many thanks.