Factor out unique tips query into a temp table