Creates DB query by name.