Messages SQL query fleshed out pretty well.