Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Data extraction - SQL
Message
 
 
À
02/09/2001 13:15:41
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00551572
Message ID:
00551615
Vues:
23
I see, somethig like this
* #1-1 , 2 conditions. Hard to expand for more than 3 conditions
SELECT CodeNo ;
  FROM mytable ;
  WHERE CertNo = 10 AND CodeNo IN (   ;
      SELECT CodeNo ;
      FROM mytable ;
      WHERE CertNo = 15)  ;
  GROUP BY 1 ;
  INTO CURSOR mycursor 

* #2-1, for 2 conditions. Works only if CodeNo+Certno combination is unique
* Can easily be expanded to any number of conditions. See next example
SELECT CodeNo ;
  FROM mytable ;
  WHERE CertNo IN ( 10, 15)  ;
  GROUP BY 1 ;
  HAVING COUNT(*) > 1 ;
  INTO CURSOR  mycursor 

* #2-2, for 3 conditions. See comments to the previous example

SELECT CodeNo ;
  FROM mytable ;
  WHERE CertNo IN ( 10, 15, 20)  ;
  GROUP BY 1 ;
  HAVING COUNT(*) > 2 ;
  INTO CURSOR  mycursor 

* #3-1, another one for 2 condition
* Can be expanded only up to 7 conditions 
*     because of the limit of 6 JOIN's per select
SELECT t1.CodeNo ;
	FROM mytable as t1 ;
		JOIN mytable as t2 ON t1.codeno = t2.codeno ;
			AND t2.certno = 15 ;
	WHERE t1.certno = 10 ;
	INTO CURSOR mycursor

* #3-3, for 3 condition

SELECT t1.CodeNo ;
	FROM mytable as t1 ;
		JOIN mytable as t2 ON t1.codeno = t2.codeno ;
			AND t2.certno = 15 ;
		JOIN mytable as t3 ON t1.codeno = t3.codeno ;
			AND t3.certno = 20 ;
	WHERE t1.certno = 10 ;
	INTO CURSOR mycursor
>Dear Sergey
>
>when the IN clause is specified it selects data even if it has satisfied only ONE of the conditions in the IN clause. What i am trying to achieve is that it should select a record only if ALL conditions are met, that is, only if condition A AND condition B AND .... are satisfied should the data be selected.
>
>thanks in advance.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform