I am using SQLAlchemy and I want to end up with a query like

select state_voter_id, last_name, first_name from voter
where
        state_voter_id in (select state_voter_id from vote
                           where vote_date = '2000-02-23' and
party_voted = 'D')
and state_voter_id not in (select state_voter_id from vote
                           where vote_date = '2004-02-21' and
party_voted = 'D')

against two tables sharing the state_voter_id foreign key:

voter (state_voter_id, last_name, first_name)
vote (state_voter_id, vote_date, party_voted)

There doesn't seem to be a "notin_" similar to "in_" that lets me do
this:

voter_db.session.query(Voter).filter(
  and_(Voter.state_voter_id.in_(select([Vote.state_voter_id],
 
and_(Vote.vote_date=='2006-09-19',
                                       Vote.party_voted == 'D'))),
       Voter.state_voter_id.notin_(select([Vote.state_voter_id],
 
and_(Vote.vote_date=='2004-09-14',
                                            Vote.party_voted ==
'D')))))

Any suggestions?

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to