Angelo Ermano
Angelo Ermano

Reputation: 3

SQL QUERY UPDATE CONDITION

I need to add one condition to this query :

UPDATE o36t_orders s 
SET s.bonifico = EXISTS (SELECT 1 
                         FROM mytable d 
                         WHERE d.Descrizione_operazione 
                         LIKE CONCAT('%', s.shipping_number,'%') )

The condition should be to do the update only if s.bonifico != 1

Upvotes: 0

Views: 48

Answers (2)

GreenTurtle
GreenTurtle

Reputation: 1262

What you probably want is this:

UPDATE o36t_orders s 
SET s.bonifico = EXISTS (SELECT 1 
                         FROM mytable d 
                         WHERE d.Descrizione_operazione 
                         LIKE CONCAT('%', s.shipping_number,'%') )
WHERE s.bonifico != 1;

Upvotes: 1

Simone Rossaini
Simone Rossaini

Reputation: 8162

You can use this code for your problem:

//CONNECT DB - FETCH RESULT
$variable=$row['s.bonifico'];
if($variable!='1'){    
UPDATE o36t_orders s SET s.bonifico = EXISTS (SELECT 1 FROM mytable d WHERE d.Descrizione_operazione LIKE CONCAT('%', s.shipping_number,'%') )
}

Upvotes: 0

Related Questions