-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) 
2
  • 2
    What does "influence all my code" mean? Why can you nod use a simple, standard WHERE clause? Commented Sep 27, 2016 at 12:48
  • 1
    What is the problem with WHERE clause? Commented Sep 27, 2016 at 12:48

3 Answers 3

1

You can use this query to achieve your constraint.

Update ExpressMarketCheck set Barcode = (select barcode from ExpressMarket where barcode IS NOT NULL) 
Sign up to request clarification or add additional context in comments.

4 Comments

Uncorrelated sub-query?
thats exactly what he doesn't want. " I dont want use where statement (is not null)"
Thanks for the info guys. Initially that constraint wasn't there when I post the answer.
Its ok i will it works with little changes in my code! Thank you!
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 

2 Comments

in SQL-Server you can use ISNULL()
thanks for pointing to it -:)
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.