SELECT o.user_id, CAST(DATE_TRUNC('month', MIN(o.created_at))AS date) FROM tools_shop.orders AS o JOIN tools_shop.events AS e ON o.user_id = e.user_id GROUP BY o.user_id;