[odb-users] Re: 2-table query

MM finjulhich at gmail.com
Mon Sep 7 12:23:10 EDT 2015


On 6 September 2015 at 22:19, MM <finjulhich at gmail.com> wrote:

> Hello,
>
> I have the following 2 tables and their relevant columns:
>
> M
> ==
> id: PRIMARY KEY
> month1: TEXT (encoded month,year combination)
> month2: TEXT
>
> F
> ==
> id: PRIMARY KEY
> mid: NOT NULL REFERENCES M("id")
> month: TEXT
>
> There can 0..N rows in F for each row in M.
>
> My question is two-fold:
>
>    1. How do I select all the F rows such that their month is 1 of the
>    2months in the relevant M row (the one where F.mid=M.id)?
>
> from stackoverflow, this is simply:

SELECT * FROM
F LEFT OUTER JOIN M ON F.mid = M.ID
WHERE (F.month = M.month1 OR F.month = M.month2)


>
>    1. How do I express this with an odb:query? Both M and F tables are
>    the mapping of c++ classes.
>
> db is sqlite. F has about 100 000 rows. The result of the query is about
> 200.
>
> Thanks,
> MM
>
Is this expressable as a high-level odb query?

typedef odb::query<F> Query;

db.query( Query::.month.in( .......... ,   ......... ) ) ?

MM


More information about the odb-users mailing list