Creates DB query.