插入不重复的值

Insert values without duplicates

我想为所有商家添加付款方式 3。我怎样才能用 MariaDB 做到这一点。

我喜欢这样:

insert into business_payment_type 
        (id_payment_type, active) 
    select "4", "1" 
    from business_payment_type 
    where id_business in (select distinct(id_business) 
                          from business_payment_type)

但是return错误:

1364 - Field 'id_business' doesn't have a default value

Table 喜欢图片

在一条语句中获取所有 id_business 值和新值,然后 INSERT 该记录集到您的 table。

INSERT INTO business_payment_type (
   id_business
  ,id_payment_type
  ,active
  )
SELECT DISTINCT
  id_business
  ,4 AS id_payment_type
  ,1 AS active
FROM business_payment_type;

I want to add payment type 3 to all businesses.

所有商家大概都在营业table。因此:

insert into business_payment_type (id_business, id_payment_type, active) 
  select id_business, 3, 1 from business;