use exists for faster sql