Hello, [Note: This is a revised edition of my previous post "multi table select"]
I have events logged to several diffeerent tables, and I need to get the union of these different tables. (The event types use different tables for various reasons.) Here is what I am doing now, and it seems to work: # Note the static 'event_type' columns stmt = 'SELECT * FROM (SELECT "A" AS event_type, user_id as user, notes, time_created ' stmt = stmt + 'FROM events_a WHERE origin_mobile_number = :uid ' stmt = stmt + 'UNION ALL ' stmt = stmt + 'SELECT SELECT "B" AS event_type, user_id as user, notes, time_created ' stmt = stmt + 'FROM events_b WHERE user_id = :uid) as events_all ' stmt = stmt + 'ORDER BY events_all.time_created DESC' res = DBSession.execute(stmt, dict(uid = uid)) records = res.fetchall() So I have several questions: 1) Is the the raw SQL I am using sane? 2) How can I use SQLAlchemy to simply things? 3) How would I add tables events_c? events_d? 4) Since the events_x tables are already defined with declarative_base, is there a reasonable way to make an SQLAlchemy "Events" object that knows where to retrieve and insert event records based on the "event_type" field? Thank you, AF --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---