I have this log table in MySQL with columns ActionName and SourceName.
The same actions can be registered multiple times from different sources.
So an example table might look like
ActionName SourceName
----------------------------
Add S01
Add S02
Add S02
Edit S01
Edit S01
Delete S01
Delete S02
Now I would like to query this table and find the actions which have been performed by both S01 and S02. So the results would be:
ActioName
--------------
Add
Delete
How would I solve this with SQL?
A specific answer…
Possibly faster for your specific question…
A general answer…
It turns out that this scales very badly though (as your table increases in size, performance plummets). You can make an optimisation though…
By holding a bit of meta-data about how selective each SourceName is…
I’d recommend keeping this talbe up to date with a trigger or something. You can then filter your ActionTable by the entry that is most restrictive, and then do the rest of the logic as normal.
Notes: