MNM MNM - 4 months ago 7
SQL Question

MySql Try to create a table from columns from two other tables

I am trying to created a table from a few columns from two other tables. I want this table to get data from the other two tables.
This is what I have so far

insert into crm_customer_coupon (barcode, customer_id,customer_name, coupon_name, number_of_times_used, product_sku)
select barcode, name, sku
From crm_coupons
Inner left Join crm_customer_extra_information where customer_id = 88


This is one of the tables rm_coupons set up

id: Barcode: Name : Description: Type : Amount : sku


This is the table rm_customer_extra_information

id : name: customer_id : ect...


and this is the table I want to put them into

barcode: customer_id : customer_name: coupon_name: product_sku


How do I go about combining them together, also how are they linked so I can get information from the other tables via a endpoint in spring later on.
Thank you for any help with this

Answer

Try this,

    insert into crm_customer_coupon (barcode,name,sku)
    select crm_coupons.barcode, crm_customer_extra_information.coupon_name, crm_coupons.sku
    From crm_coupons
    left Join crm_customer_extra_information on crm_coupons.id=crm_customer_extra_information.id
where customer_id = 88 

You forgot to mention you join field (i guess it's id), also you didn't mention which name field you want to insert , i put coupon_name , you can change the filed name in the subquery select