Best Algorithm/Approach for Comparing SQL Queries to Check if They Solve the Same Problem?

Hello, I'm working on a project where I need to compare SQL queries to determine if both queries actually resolve the same problem/exercise. Essentially, I want to check if they return the same result set for any given input, even if they use different syntax or structures (e.g., different JOIN orders, subqueries vs. CTEs, etc.).

I know that things like execution plans might differ, but the result set should ideally be the same if both are solving the same problem. Does anyone know of a reliable algorithm or approach for doing this? Maybe some clever SQL transformation, normalization technique, or even a library/tool that can help?

The main objective is to build a platform where the system has a stored solution. And the user should insert theirs and the system should compare both and determine if the entered query is a possible and valid response.

Thanks in advance for any suggestions! 🙏