Find first-time purchases with certain category
My educated guess:

SELECT *
FROM (
   SELECT DISTINCT ON (o.guest_email)
          o.guest_email AS "Email", o.date_purchased AS "First Purchase", mc.name AS "Category"
   FROM   order_order               o
   JOIN   order_line                l  ON l.order_id = o.id 
   JOIN   catalogue_productcategory p  ON p.product_id = l.product_id
   JOIN   catalogue_category        c  ON c.id = p.category_id
   JOIN   catalogue_category        mc ON mc.path = left(c.path, 4)
   ORDER  BY o.guest_email, o.date_purchased
   ) sub
WHERE  "Category" = 'Computer';


Or, if all those joins never exclude rows (referential integrity enforced with FK constraints), you can exclude irrelevant rows early:

SELECT o.guest_email AS "Email", o.date_purchased AS "First Purchase", mc.name AS "Category"
FROM  (
   SELECT DISTINCT ON (guest_email)
          id, guest_email, date_purchased  -- more columns?
   FROM   order_order
   ORDER  BY guest_email, date_purchased
   ) o
JOIN   order_line                l  ON l.order_id = o.id 
JOIN   catalogue_productcategory p  ON p.product_id = l.product_id
JOIN   catalogue_category        c  ON c.id = p.category_id
JOIN   catalogue_category        mc ON mc.path = left(c.path, 4)
WHERE  mc.name = 'Computer';


I largely rewrote the query and removed some cruft.

The subquery retrieves the first order per email.
The outer query filters first-timers who bought a 'Computer'.

About DISTINCT ON:


Select first row in each GROUP BY group?


Depending on your complete situation, there may be faster query techniques:


Optimize GROUP BY query to retrieve latest record per user