-1

I want update a column(a) from table1 with select from table2 but making update only when in table2 existing column(b) is not null. I dont want use where statement (is not null) cause it will influence all my code.

Example of my code:

update table1 set column(a) = (select column(b) from table2)

I'm trying something like this

update table1 set column(a) = not null(select column(b) from table2)

Example:

update ExpressMarketCheck set Barcode = (select barcode from ExpressMarket), Name=(select name from expressmarket), price=(select price from expressmarket)
DiH
  • 331
  • 2
  • 7
  • 17

3 Answers3

1

You can use this query to achieve your constraint.

Update ExpressMarketCheck set Barcode = (select barcode from ExpressMarket where barcode IS NOT NULL)
vignesh
  • 83
  • 8
1

mySQL has an IFNULL function, so you could do:

UPDATE your_table_name
SET your_column_name= "data",
scan_created_date = ISNULL( your_column_name, "data" )
WHERE id = X
Muhammad Usman
  • 9,766
  • 21
  • 39
1

I think you want a join:

update emc
    set Barcode = em.barcode, 
        Name = em.name,
        price= em.price
     from ExpressMarketCheck emc join
          expressmarket em
          on emc.?? = em.??;

I cannot tell from your question what columns should be used for the join. The ?? are placeholders.

Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709