Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Performance - union
Message
 
 
À
02/02/2012 06:32:02
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01534182
Message ID:
01534296
Vues:
44
Hey, I never said it was just a matter of replacing one word with another.

>Which confirms that you cannot just replace EXISTS with a JOIN
>
>>And?
>>
>>>With JOIN and DISTINCT also. But you have to add DISTINCT.
>>>
>>>
>>>>You just confirmed that it can be done with LEFT JOIN with DISTINCT.
>>>>
>>>>>
>>>>>Ok, There is a parent table and a child table. The child table contains a link to its parent
>>>>>
>>>>>
>>>>>	create cursor parent ;
>>>>>	(	p_id		I, ;
>>>>>		p_name		c(32) ;
>>>>>	)
>>>>>	
>>>>>	insert into parent  values (1, 'Father Tom')
>>>>>	insert into parent  values (2, 'Father Mike')
>>>>>	
>>>>>	create cursor Child ;
>>>>>	(	c_id		I, ;
>>>>>		c_p_id		I, ;
>>>>>		p_name		c(30) ;
>>>>>	)
>>>>>	
>>>>>	insert into Child values (1, 2, 'Daniel')
>>>>>	insert into Child values (2, 2, 'David')
>>>>>
>>>>>
>>>>>I want to find the parents that have children
>>>>>
>>>>>
>>>>>(1) With exists
>>>>>
>>>>>	select * ;
>>>>>		from Parent ;
>>>>>		where	( exists ;
>>>>>					( select 1 from Child  where c_p_id == p_id ) ;
>>>>>				) ;
>>>>>		into cursor ParentsWithChildren
>>>>>
>>>>>
>>>>>(2) How would you get the same result with JOIN or LEFT JOIN ? - no fiddling with DISTINCT
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform