[Ur] outer join + inner sql request
Sergey Mironov
grrwlf at gmail.com
Sat Oct 18 15:36:16 EDT 2014
Oh, looks like I've found the solution: we have to rename returned
fields of inner SQL to make urweb happy. The correct query is
SELECT *
FROM groups AS G LEFT OUTER JOIN
(SELECT CG.GId AS GId FROM
compet_groups AS CG WHERE CG.CId = {[cid]}) AS CG ON CG.GId = G.Id
Note "CG.GId AS GId" part
Regards,
Sergey
2014-10-18 23:19 GMT+04:00 Sergey Mironov <grrwlf at gmail.com>:
> Hi! I want to write a complex SQL request that would outer join two
> tables after applying a filter to one of them. Here is the prototype:
>
> table groups : ([Id = int] ++ ... (*not important*) )
> table compet_groups : ([CId = int, GId = int])
>
> query(
> SELECT *
> FROM groups AS G LEFT OUTER JOIN (SELECT * FROM
> compet_groups WHERE CId = 1) AS CG ON CG.GId = G.Id
> )
>
> Unfortunately, attempting to compile it fails with an error
>
> /home/grwlf/proj/urweb-homepage/lib/urweb-compet/src/Compet.ur:459:44:
> (to 460:17) Error in final record unification
> Can't unify record constructors
> Have: [Compet_groups = [CId = int, GId = int]]
> Need: []
>
>
> I've tried the same query with [psql] and it worked. Is there anything
> I can do to implement this logic in Ur/Web?
>
> Regards,
> Sergey
More information about the Ur
mailing list