Hi
I have a table that can contain numerous records with the same transaction id, each of which can be set to one of a number of statuses. I would like a query that will only select me transaction ids where they are all set to a specified status.
For example, for this table (run this in Query Analyzer)
I would like a query which returns me trans_id 2, and nothing else, if I specify that I want all transactions where the status is all set to 2.
Can anybody help me?
I have a table that can contain numerous records with the same transaction id, each of which can be set to one of a number of statuses. I would like a query that will only select me transaction ids where they are all set to a specified status.
For example, for this table (run this in Query Analyzer)
Code:
declare @t table(trans_id int, status int)
insert @t values(1, 1)
insert @t values(1, 2)
insert @t values(1, 2)
insert @t values(2, 2)
insert @t values(2, 2)
insert @t values(2, 2)
insert @t values(3, 1)
insert @t values(3, 1)
insert @t values(3, 1)
select trans_id, status from @t
I would like a query which returns me trans_id 2, and nothing else, if I specify that I want all transactions where the status is all set to 2.
Can anybody help me?