Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Performance - union
Message
From
02/02/2012 06:32:02
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01534182
Message ID:
01534267
Views:
50
Likes (1)
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
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform