Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What is the point of the cross join? This would work as well:

   SELECT loop.value, loop.value * loop.value
   FROM generate_series(1,5) AS loop(value)


For this example, nothing. It would be useful where neither of the two SELECT queries is a subset/superset of the other. (Not saying you didn't know that.)


Could you give an example?


This will be useful if you have a table with some related history records, e.g., products with product price history, and you want to get the latest price. The lateral join would get all prices for the current product, sort them by date and then pick the top row.


How does a lateral (cross) join compare to a window function in your example?


Is a lateral join more efficient than just saying where product = current sort by date desc ?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: