Wrong sql lookup, needed more granularity