clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1926624 fiddles created (21827 in the last week).

CREATE TABLE tablename ( Subject INTEGER, ActionID VARCHAR(1), ActionOrder INTEGER ); INSERT INTO tablename (Subject, ActionID, ActionOrder) VALUES ('1', 'A', '1'), ('1', 'C', '2'), ('1', 'D', '3'), ('1', 'B', '4'), ('1', 'C', '5'), ('2', 'D', '1'), ('2', 'A', '2'), ('2', 'C', '3'), ('2', 'B', '4'), ('3', 'B', '1'), ('3', 'D', '2'), ('3', 'A', '3'), ('4', 'A', '1');
13 rows affected
 hidden batch(es)


SELECT Subject FROM tablename WHERE ActionID IN ('A', 'B') GROUP BY Subject HAVING MAX(CASE WHEN ActionID = 'A' THEN ActionOrder END) < MIN(CASE WHEN ActionID = 'B' THEN ActionOrder END)
Subject
1
2
Warning: Null value is eliminated by an aggregate or other SET operation.
 hidden batch(es)