I have a relation in PostgreSQL named product which contains 2 fields: id and quantity, and I want to find the id of the
I tried your methods in postgres (test table distributed by id). That first method ran much slower for me. Here were my comparison results:
Method 1 above: 3.1 seconds
Method 2 above: 0.13 seconds
Method 1 was at least 10 times slower in repeated efforts. I think your method 2 is the better option, as the sub-query likely runs much faster than the sub-query in the other option.