Last query entirely by database