generalizing a query to work for all DBs