Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to make such query?
Message
De
25/12/2005 10:16:35
 
 
À
25/12/2005 03:40:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01080746
Message ID:
01080770
Vues:
13
>REMEMBER THIS:
>you can transform the "not in" or "not exists" condition in an INNER JOIN,
>into a LEFT JOIN with a WHERE IS NULL condition.
>
>select
>...
>from trans T INNER join Trans_Employees_Queues Q on T.cTrans_pk = Q.cTrans_fk
>INNER JOIN ....
>LEFT JOIN Employee_Queue_Schedules S ON S.FK=
>WHERE .... and S.FK IS NULL
>
>
________________________________
Fabio,

Shouldn't that be HAVING instead of WHERE ?

WHERE decides what records to include from the table(s), ie where defines the subset of each table that will participate in the select

HAVING decides what records to keep in the final resultset (ie after the WHERE and OUTER JOIN have been applied)

So, since no records have (fk is null), no records will pass the WHERE clause. Look at the output of (3)

As far as I can see, the sequence is WHERE - OUTER JOIN - HAVING
create cursor Customer (c_id I)
	insert into Customer values(1)
	insert into Customer values(2)
	
	Create cursor Orders( ord_id I, Ord_c_id I )
	
	insert into Orders values (22, 2)
	insert into Orders values (24, 2)
	
	&& find customers without order(s)
	
	&& (1)
	select	c_id ;
		from Customer ;
		into cursor tmp1 ;
		where	( not exists ;
					(select * from Orders where (Ord_c_id = c_id) ) ;
				);
				
	brow
	
	&& (2) left join, with having
	select	c_id, ;
			ord_id ;
		from Customer ;
			left join Orders on (Ord_c_id = c_id) ;
		into cursor tmp2 ;
		having ( ord_id is null ) 
	
	brow
	
	
	&& (3) left join, with where
	select	c_id, ;
			ord_id ;
		from Customer ;
			left join Orders on (Ord_c_id = c_id) ;
		into cursor tmp3 ;
		where ( ord_id is null ) 
	
	brow
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform