implement subject matching as an SQL limit w/ group by and having