Dynamically compare data in a table