Howdy,

I've got this SQL query:

select *
from
( select a1.domain_id as domain_id_1, u1.eid as eid, u1.uname as
uname,
        u1.uid as uid, a1.gcos, a1.home, a1.shell
    from nis_accounts a1 inner join nis_users u1 on (a1.nis_user_id =
u1.id)
    where u1.eid != ''
) ndu1
inner join
( select a2.domain_id as domain_id, u2.eid as eid, u2.uname as uname,
        u2.uid as uid, a2.gcos, a2.home, a2.shell
    from nis_accounts a2 inner join nis_users u2 on (a2.nis_user_id =
u2.id)
    where u2.eid != ''
) ndu2
on (ndu1.eid = ndu2.eid and ndu1.uid != ndu2.uid)
where ndu1.eid in (
    select eid from nis_users
    group by eid
    having count(uid) > 1 and eid != '' and uname not like '%_old'
) and domain_id_1 = 45

And am trying to represent it in sqlalchemy python speak.

I can get

( select a2.domain_id as domain_id, u2.eid as eid, u2.uname as uname,
        u2.uid as uid, a2.gcos, a2.home, a2.shell
    from nis_accounts a2 inner join nis_users u2 on (a2.nis_user_id =
u2.id)
    where u2.eid != ''
) ndu2

translated to:

s = select([nis_accounts_table, nis_users_table],
 
from_obj=[nis_accounts_table.join(nis_users_table)]).where(nis_users_table.c.eid
 !
= '')

Which can give me two selects using aliases:

a1 = s.correlate(None).alias()
a2 = s.correlate(None).alias()

But every attempt at using a1 and a2 in a select with a join is
failing for me.

I'm sure I'm missing something here.

Help and pointers will be greatly appreciated.

Thanks,

Jeff.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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