Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using self-join to merge rows into same column
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01239953
Message ID:
01240040
Views:
9
My message #1239975 in this thread shows how to do it using JOINs. You've to adjust it a litle bit to your new requirements.
You may also reconsider using EMPTY() function because it's not optimizable
SELECT vehicles.order_key, ;
		NVL(lm.lup_value, SPACE(10)) AS Make,  ;
		NVL(lc.lup_value, SPACE(10)) AS Color ;
	FROM vehicles ;
	LEFT JOIN lookup lm ;	
		ON lm.lup_id = vehicles.make_key ;
	LEFT JOIN lookup lc ;	
		ON lc.lup_id = vehicles.color_key ;
	WHERE NOT EMPTY(vehicles.make_key) OR NOT EMPTY(vehicles.color_key)
>
>The different ideas gave me a lot to think about. (I put them all together for later reference) As a result, though, I was able to come up with the following solution that pulls everything into a cursor in one step instead of the two I had originally:
>SELECT vehicles.order_key, ;
>   (SELECT lup_value FROM lookup ;
>   	WHERE lookup.lup_id = vehicles.make_key) as make, ;
>   (SELECT lup_value FROM lookup ;
>	WHERE lookup.lup_id = vehicles.color_key) as color ;
>	FROM vehicles WHERE ;
>	! EMPTY(vehicles.make_key) or ! EMPTY(vehicles.color_key)
>
>Does anyone know how to do the exact same thing as above but changing the syntax using joins? Just so I can understand the join concept better.
>
>Thanks again all of you for your time.
>
>Marcel
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform