I am joining a large table in postgresql to a table with 1 row in it. Yes, I know I could just take the values from this single row table and put them in my query written out, but there's 210 columns.
So my question is this: should I join up the single row table to everything using a cross join or using a regular join on a tautology (1 = 1 or something). Is either of those ways bound to be slower?
Or is there a third faster way?
1. Natural Join joins two tables based on same attribute name and datatypes. Cross Join will produce cross or cartesian product of two tables . 2.
What does ON 1=1 mean here? It just ensures the join will return a match -- 1=1 is the same as true . Given the subquery, it will only return a single row -- min(modified) . That value will be combined to the other joins.
The CROSS JOIN is used to generate a paired combination of each row of the first table with each row of the second table. This join type is also known as cartesian join. Suppose that we are sitting in a coffee shop and we decide to order breakfast.
One thing to note is a cross join will result in an empty table if one of the tables is empty. If one of your tables might be empty and you still want records, you may want an outer join (e.g. left, right, or full) on 1=1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With