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:
01676144
Vues:
75
This message has been marked as the solution to the initial question of the thread.
>>>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
>>You can't have more than one field selected in IN clause
>>
>>in (select Table2.Field1, Table2.Field2 FROM...
>>
>>should be:
>>
>>in (select Table2.Field1 FROM ...
>>
>
>First, thank you.
>
>But if I have only one field in the Select Table2.Field1, then how do I have the last part:
>Table2.Field2 in (select Table3.Field2 from Table3)?
>
>That is, in order for me to select from Table3, don't I have to have the field Table2.Field2?

You must have Field2 in Table2, but not in SELECTed fields :-)
CREATE CURSOR Table1 (Field1 int)
CREATE CURSOR Table2 (Field1 int, Field2 int)
CREATE CURSOR Table3 (Field1 int, Field2 int)

SELECT Table1.*;
FROM Table1;
WHERE Field1 IN (SELECT Field1 FROM Table2;
                        WHERE Field2 IN (SELECT Field2 FROM Table3))
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform