Fixed queries for sqlite