checks if a value exists in a table