Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select with 2 IN clauses
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01676141
Message ID:
01676147
Vues:
37
>>Hi,
>>
>>I am running into a problem where the error message is:
>>
>>Only one expression can be specified in the select list when the
>>subquery is not introduced with EXISTS
>>
>>
>>The SQL Select is as follows:
>>
>>select Table1.Field1 from Table1 where Tabel1.Field1 in (select Table2.Field1, Table2.Field2 from Table2 where 
>>Table2.Field2 in (select Table3.Field2 from Table3))
>>
>>
>>That is, in the above SQL Select there are two IN clauses.
>>
>>Does the error mean that I have to change the second IN with EXISTS? Or both IN have to be change to EXISTS?
>>
>>TIA
>
>
>In your example EXISTS() should perform much faster than IN(). So if the tables are large you might consider:
>
>
>select Table1.Field1 from Table1 
>    where EXISTS(select null from table2 join table3 on table2.field2 = table3.field2 and table2.field1 = table1.field1)
>
>
>Exists will stop looking once it found a match, and the inner join of table2 and table3 automatically filters records that exist in both tables.

I didn't know that Exists is faster than IN(). My tables are not very large. I am testing on the tables of about 3000 rows. I believe that for the largest customer, the tables will not be much larger than 15000 rows.
But I will try your approach. I am always more concerned about making a mistake in the syntax than the speed of execution. 1 second vs 10 seconds - for my customers - does not make a huge difference. But if I can make the code more efficient, why not.
Thank you very much.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform