On Saturday, December 15, 2012 2:04:28 PM UTC-6, Mamisoa Andriantafika wrote: > > Thank you for your answer. > > What do you mean by: > 1) too many records: I have about 1k per dataset >
I mean the sorting I suggested is performed in ram, in Python. If that is not slow than ok. > 2) database view? > http://stackoverflow.com/questions/3267360/data-from-two-tables-into-one-view You can create the view outside web2py and create a corresponding web2py model with (migrate=False) and use it to select but not/insert/delete/update. > > > Le samedi 15 décembre 2012 20:23:44 UTC+1, Massimo Di Pierro a écrit : >> >> If you have lots of records you may be able to do it with a database view >> but that may be db specific. >> >> If you don't have too many records you can do: >> >> rows = ( db(db.dataset1).select() | db(db.dataset2).select() >> ).sort(lambda row: row.date) >> >> >> >> On Saturday, 15 December 2012 08:43:35 UTC-6, Mamisoa Andriantafika wrote: >>> >>> Hi, >>> >>> I have this db model: >>> >>> db.define_table('patients', >>> Field('name', 'string', length=32), >>> Field('firstname', 'string', length=32), >>> Field('dob', 'date'), >>> format='%(name)s') >>> >>> db.define_table('dataset1', >>> Field('date', 'date', length=32), >>> Field('param1', 'string', length=50), >>> Field('param2', 'string', length=50), >>> Field('patient_id', db.patients, writable=False, readable=False)) >>> >>> db.define_table('dataset2', >>> Field('date', 'date', notnull=True), >>> Field('test1', 'text'), >>> Field('patient_id', db.patients, writable=False, readable=True)) >>> >>> I'd like to show in one view, for 1 patient_id, all the corresponding >>> dataset1 and dataset2 ordered by date. >>> >>> What query should I use? Do I have to use an intermediate table >>> 'history' to record each activity in dataset1/2 to get a result? >>> >>> Thanks for help. >>> >> --