Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using self-join to merge rows into same column
Message
 
 
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 SP1
Divers
Thread ID:
01239953
Message ID:
01239975
Vues:
7
SELECT DISTINCT mt1.order_key, ;
		NVL(mtm.lup_value, SPACE(10)) AS Make,  ;
		NVL(mtc.lup_value, SPACE(10)) AS Color ;
	FROM mytable mt1 ;
	LEFT JOIN mytable mtm ;	
		ON mt1.order_key  = mtm.order_key ;
			AND mtm.lup_type = "make" ;
	LEFT JOIN mytable mtc ;	
		ON mt1.order_key  = mtc.order_key ;
			AND mtc.lup_type = "color"
>I have a cursor with 3 fields order_key, lup_type, lup_value.
>The data might look as follows:
>531 make FORD
>531 color BLUE
>532 make HONDA
>532 color RED
>533 color ORANGE (person didn't enter a car make)
>534...etc.
>
>These values were already retrieved from a vehicle_info table and a lookup table.
>
>How can I take these values and combine them so that it will have the following layout:
>
>order_key, veh_make, veh_color
>531, FORD, BLUE
>532, HONDA, RED
>533, , ORANGE
>
>I tried a self join but can't get the list to show unique order_key's.
>
>As always, thanks for your excellent help.
>
>Marcel
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform