Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Performance - union
Message
 
 
To
02/02/2012 06:00:15
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01534182
Message ID:
01534264
Views:
46
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
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform