Subject Looking for help with query and SINGULAR
Author nitaligavino
Hello all:

I need some help creating a query for the following:
I have a table named Media with several columns populated as follows:

MKey MAction MStoreId
1 2 4
2 1 4
3 1 6

I need to get a result set from this table only when all items for a
particular MStoreId are in the MAction = 2 state. However, I don't
have any input data. So I don't know the store id's.

So using the above data, my result set would be empty because MAction
= 1 for MKey 2. However, when MAction is set to 2 for MKey 2, I
would then expect a results set containing row 1 and row 2 because
all items for MStoreId 4 are in the MAction state of 2.

Kind of like saying: (pseudo sql)
Select all items where the MStoreId is the same and MAction state is
also 2.

I have written several queries that worked, using views, etc.,
however their performance was terrible. I was using a WHERE IN
clause which was extremely slow.

Anyway, I thought the following would work:

SELECT * FROM Media WHERE MAction = 2
AND NOT EXISTS (SELECT * FROM Media WHERE MAction = 1)

I must not understand the EXISTS clause because this does not produce
the results that I had hopped??

I have also tried:
SELECT * FROM Media WHERE MAction = 2
AND SINGULAR (SELECT * FROM Media WHERE MAction = 1)

Which seems to work but I don't know why? What is this SINGULAR
clause?

Can anyone suggest a simple why to get this result set?

Thanks for the help!
Dan