Kolomnamen achterhalen (MySQL): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 14: Regel 14:
 
</pre>
 
</pre>
  
Of uitvoeren als één string:
+
Of uitvoeren als één string - inclusief voorbeeld-output:
  
 
<pre>
 
<pre>
 
select group_concat(column_name) from information_schema.columns  
 
select group_concat(column_name) from information_schema.columns  
 
where table_name="amazon_de_tmp" and table_schema="webwinkels";
 
where table_name="amazon_de_tmp" and table_schema="webwinkels";
 +
 +
item_sku,external_product_id,external_product_id_type,asin,item_name_de,manufacturer,feed_product_type,brand_name,part_number,description_de,update_delete,standard_price_de,quantity,fulfillment_latency,condition_type,number_of_items,website_shipping_weight,website_shipping_weight_unit_of_measure,item_length,item_width,item_height,item_dimensions_unit_of_measure,item_weight,item_weight_unit_of_measure,recommended_browse_nodes,generic_keywords,bullet_point1,bullet_point2,bullet_point3,bullet_point4,bullet_point5,target_audience_keywords,main_image_url,other_image_url1,package_height,package_height_unit_of_measure,package_width,package_width_unit_of_measure,package_length,package_length_unit_of_measure,package_weight,package_weight_unit_of_measure,color_name,color_map,material_type,specific_uses_for_product,item_name,description,standard_price
 
</pre>
 
</pre>
  

Versie van 11 mei 2016 11:47

Kolomnamen achterhalen is simpel

select column_name from information_schema.columns where table_name="tabelnaam" and table_schema="databasenaam";

Of wegschrijven in een tijdelijke tabel:

drop table if exists tmp;
create temporary table tmp select column_name 
from information_schema.columns 
where table_name="tabelnaam" and table_schema="databasenaam";

Of uitvoeren als één string - inclusief voorbeeld-output:

select group_concat(column_name) from information_schema.columns 
where table_name="amazon_de_tmp" and table_schema="webwinkels";

item_sku,external_product_id,external_product_id_type,asin,item_name_de,manufacturer,feed_product_type,brand_name,part_number,description_de,update_delete,standard_price_de,quantity,fulfillment_latency,condition_type,number_of_items,website_shipping_weight,website_shipping_weight_unit_of_measure,item_length,item_width,item_height,item_dimensions_unit_of_measure,item_weight,item_weight_unit_of_measure,recommended_browse_nodes,generic_keywords,bullet_point1,bullet_point2,bullet_point3,bullet_point4,bullet_point5,target_audience_keywords,main_image_url,other_image_url1,package_height,package_height_unit_of_measure,package_width,package_width_unit_of_measure,package_length,package_length_unit_of_measure,package_weight,package_weight_unit_of_measure,color_name,color_map,material_type,specific_uses_for_product,item_name,description,standard_price

Kolomnamen naar één record wegschrijven

Maar nu wil ik de namen naar verschillende velden in één record in een tabel schrijven, bv. om deze veldnamen als heading te gebruiken. Liefst zonder de kolomnamen te moeten benoemen.

Bronnen