You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY pg.sort ASC LIMIT 1' at line 8
string(247) "SELECT pg.productgroupid AS id, pg.shorturl AS url FROM productgroup pg JOIN productgroups_products pg_rel ON pg.productgroupid = pg_rel.productgroup_id AND pg_rel.product_id = ORDER BY pg.sort ASC LIMIT 1;"