Sébastien LELONG ha scritto:
>> As you can see the from_obj of subselect is wrong, the FROM should be:
>>
>> FROM azienda_veterinario, unita_aziendale
>>     
>
> OK, I see... You probably mean that since your sub-select occurs on two 
> tables, those have to be present in the FROM clause. I've tested this kind on 
> query (select a from A where a in (select b from B where a = b)) and this 
> works ok (MySQL). Your sub-query becomes invalid if taken alone, but the 
> whole keeps correct. What's the error when performing manually the query 
> (using mysql client or the like) ?
>
> Seb
>   
I know it works but the problem is the performance.

this query takes 0m31.073s:

SELECT unita_aziendale.id
FROM unita_aziendale
WHERE unita_aziendale.id IN (SELECT 
azienda_veterinario.id_unita_aziendale AS id_unita_aziendale
FROM azienda_veterinario
WHERE azienda_veterinario.id_veterinario = 3 AND 
azienda_veterinario.id_unita_aziendale = unita_aziendale.id AND 
azienda_veterinario.data_inizio IS NOT NULL AND 
azienda_veterinario.data_fine IS NULL)

this one takes 0m0.686s

SELECT unita_aziendale.id
FROM unita_aziendale
WHERE unita_aziendale.id IN (SELECT 
azienda_veterinario.id_unita_aziendale AS id_unita_aziendale
FROM azienda_veterinario, unita_aziendale
WHERE azienda_veterinario.id_veterinario = 3 AND 
azienda_veterinario.id_unita_aziendale = unita_aziendale.id AND 
azienda_veterinario.data_inizio IS NOT NULL AND 
azienda_veterinario.data_fine IS NULL)

jo



--~--~---------~--~----~------------~-------~--~----~
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