Made correct database query