Hello list,
I'm trying to generate a query similar to the following:
SELECT foo, bar, baz FROM (SELECT foo FROM ... WHERE ...) AS tmp1 INNER JOIN (SELECT bar FROM ... WHERE ...) AS tmp2 ON (tmp1.id = tmp2.id) INNER JOIN (SELECT baz FROM ... WHERE ...) AS tmp3 ON (tmp2.id = tmp3.id)
How can I express this in S-SQL syntax?
TIA Ralf Mattes
Hello Ralf,
Try...
(s-sql:sql (:select 'foo 'bar 'baz :from (:as (:select 'foo :from 'x :where 'x) 'tmp1) :inner-join (:as (:select 'bar :from 'x :where 'x) 'tmp2) :on (:= 'tmp1.id 'tmp2.id) :inner-join (:as (:select 'baz :from 'x :where 'x) 'tmp3) :on (:= 'tmp2.id 'tmp3.id)))
... which gives ...
"(SELECT foo, bar, baz FROM (SELECT foo FROM x WHERE x) AS tmp1 INNER JOIN (SELECT bar FROM x WHERE x) AS tmp2 ON (tmp1.id = tmp2.id) INNER JOIN (SELECT baz FROM x WHERE x) AS tmp3 ON (tmp2.id = tmp3.id))"
Cheers, Marijn
On Wed, 2007-10-17 at 17:09 +0200, Marijn Haverbeke wrote:
Hello Ralf,
Hey, thanks! That was a fast reply ;-) Yes, that seems to work fine. Thanks a lot
RalfD
Try...
(s-sql:sql (:select 'foo 'bar 'baz :from (:as (:select 'foo :from 'x :where 'x) 'tmp1) :inner-join (:as (:select 'bar :from 'x :where 'x) 'tmp2) :on (:= 'tmp1.id 'tmp2.id) :inner-join (:as (:select 'baz :from 'x :where 'x) 'tmp3) :on (:= 'tmp2.id 'tmp3.id)))
... which gives ...
"(SELECT foo, bar, baz FROM (SELECT foo FROM x WHERE x) AS tmp1 INNER JOIN (SELECT bar FROM x WHERE x) AS tmp2 ON (tmp1.id = tmp2.id) INNER JOIN (SELECT baz FROM x WHERE x) AS tmp3 ON (tmp2.id = tmp3.id))"
Cheers, Marijn
postmodern-devel@common-lisp.net