Whenever you want to invert a function you should think about Lagrange inversion. In this case you want to invert a quadratic function. Lagrange inversion happens to have an elegant proof using trees which can be found, for example, in Stanley's Enumerative Combinatorics (Vol. II). This proof interprets an implicit identity satisfied by a generating function (such as the one satisfied by the generating function for the Catalan numbers) as recursively describing a certain kind of tree; for much more on this point of view, see Bergeron, Labelle, and Leroux's Combinatorial Species and Tree-Like Structures. Specializing to this case gets you one of the flavors of trees counted by the Catalan numbers. 

(But this is not the train of thought that would have actually occurred to me because the Catalan numbers are more familiar than Lagrange inversion; I just look for $\sqrt{1 - 4x}$ everywhere, and in this problem I see $\sqrt{ \frac{1}{4} - x}$, so... )

Intuition Behind a Decimal Representation with Catalan Numbers
I don't really know how to explain except with "vertical where".

Imagine the following table:

TAGID|PRODUCTID|SHOP_ID
59   |3418-7   |38
61   |3418-7   |38
60   |4227-4   |38
61   |4227-4   |38


Now I want to return all product IDs, that have relation to the tag IDs: 59,61. In other words, values of product ID where rows exist for both tag IDs.

So I want to return 3418-7, but not 4227-4

How do I write this as simple as possible in a SQL statement?

This is the working statement I have so far, but I feel this could be done in a much smarter way:

SELECT 
  productid 
FROM shop_tag_relations 
WHERE 
  productid IN (select productid from shop_tag_relations WHERE tagid=59) 
AND 
  productid IN (select productid from shop_tag_relations WHERE tagid=61)
GROUP BY productid,shop_id

