Fix join query in getDB