Closed Jaymon closed 1 year ago
We could also have a shortcut syntax:
Foo.query.intersect_pk(
[("type", "a"), ("value", "1")],
[("type", "b"), ("value", "2")],
)
Notice that intersect_pk
that is what field should be selected. Not sure how to do it to select multiple fields
Limit and offset syntax:
SELECT * FROM (
SELECT
"_id"
FROM
"foo"
WHERE
("type" = 'a' AND "value" = '1')
INTERSECT
SELECT
"_id"
FROM
"foo"
WHERE
("type" = 'b' AND "value" = '2')
) I LIMIT 5 OFFSET 0
There is also UNION
and UNIONALL
you could use in place of INTERSECT
, all the syntax seems to be the same
If the individual queries need to be limited or anything, they should be enclosed in parens:
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10)
An intersect query:
and a count query:
This could be done in prom:
References
Search