Skip to content
Advertisement

How do I partially share param values across union selects using different constraints?

I have a view

Which is at least unique for car.id

Now I want to union 3 different queries into a second view, which takes user set parameters:

The above does not work as the 2nd query has no access to the the 1st one. As the constraints change, I believe I cannot use a CTE. What are my options?

Advertisement

Answer

Since the requirements are vague, I can’t say for sure that the following solution is complete, however, I would look into breaking the p0, p1, p2 into with clause sub queries that way you can use p0 in p1 and p2. For example:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement