Skip to content
Advertisement

Performing a JOIN with the results of a WITH clause

I have one query that uses one join already, call it query1. I would like to join query1 to the results of a WITH clause. I don’t know how to merge the two data sets.

Query 1:

The next query is a WITH clause. I don’t know how to obtain the results without a WITH because I need to do what is outlined in this post.

Query 2:

I thought I could just JOIN ranked_DateStamp ON ranked_DateStamp.NodeID = p.NodeID but it won’t allow it.

Advertisement

Answer

You don’t really need a with clause here, you can use a subquery. I would just phrase this as:

However, if you were to use a common table expression, that would look like:

Actually, a lateral join might perform equally well, or better:

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