I have table - config.
Schema:
config_name | config_value
And I would like to update multiple records in one query. I try like that:
UPDATE config
SET t1.config_value = 'value'
, t2.config_value = 'value2'
WHERE t1.config_name = 'name1'
AND t2.config_name = 'name2';
but that query is wrong :(
Can you help me?
Try either multi-table update syntax
Here is SQLFiddle demo
or conditional update
Here is SQLFiddle demo
in my case I have to update the records which are more than 1000, for this instead of hitting the update query each time I preferred this,
78,77 are the user Ids and for those user id I need to update the base_id 999 and 88 respectively.This works for me.
Camille's solution worked. Turned it into a basic PHP function, which writes up the SQL statement. Hope this helps someone else.
You can accomplish it with INSERT as below:
This insert new values into table, but if primary key is duplicated (already inserted into table) that values you specify would be updated and same record would not be inserted second time.
maybe someone it will be useful
for Postgresql 9.5 works as a charm
this SQL update existing record and insert new (2 in one)
Execute the below code if you want to update all record in all columns:
and if you want to update all columns of a particular row then execute below code: