Questions tagged [sql-update]

An SQL UPDATE statement is used to change existing rows in a table.

An SQL UPDATE statement is used to change existing rows in a table.

The basic syntax is:

UPDATE table 
SET 
    Column1 = 'x',
    Column2 = 'y'
WHERE id=1

Tagging Recommendation

This tag should be used for general SQL programming language questions, in addition to tags for specific products. For example, questions about Microsoft SQL Server should use the tag, while questions regarding MySQL should use the tag. Tagging by product (including version, e.g , ) is the easiest way to know what functionality is available for the task at hand.

References

12009 questions
2
votes
1 answer

Is mysql update on join table consistent?

I have two tables t1 and t2 with primary key id and integer amount each. I need to "move" amounts from t2 to t1, but not lost any amounts and not get extra. Is it possible by single update with autocommit and without transaction isolations? I mean…
Pavel G
  • 21
  • 4
2
votes
3 answers

Is there "UPDATE value IF NO SUCH ROW INSERT yyy" in MySQL?

I want to update a table value on Mysql 5 but if the key does not exist create it. The way I found to do it is by: INSERT yyy ON DUPLICATE KEY UPDATE field; The question is : is the format above less efficient than other ways to do it (As the…
Nir
  • 24,619
  • 25
  • 81
  • 117
2
votes
3 answers

Basic SQL query - Replacing data in one table column with updated data from another, earlier backup

I'm a complete newcomer to this kind of thing, hence the simple question, but I have 2 copies of a database table which I need to combine somewhat. Both have the exact same structure and contain member account usernames and details. In one column…
jontly
  • 238
  • 1
  • 4
  • 12
2
votes
2 answers

SQL UPDATE statment

I have this query that returns me ids select id, default_code from product_product ou where (select count(*) from product_product inr where inr.default_code = ou.default_code) > 1 and ou.active = false but i'm getting syntax error with this…
Chaban33
  • 1,362
  • 11
  • 38
2
votes
6 answers

Update in Oracle 11g

I have to update a field in a table. I'm using following queries. Help me, which one is right? update table1 set col1=,col2=.... from table1 t,table2 s where t.id=s.num and s.code='abc'; or update table1 set…
renu
2
votes
4 answers

SQL query, update from, multiple inner join

lets say I have 3 tables in my SQL database: AspNetUserRoles - hold records that links user with role AspNetUsers - holds users AspNetRoles - holds roles I wanted to update role assigned to user whose email is: some@email.com I created this query…
Matthewek
  • 1,519
  • 2
  • 22
  • 42
2
votes
1 answer

Update Mysql column field from a table based on user id

I am new to PHP and SQL, at the moment I am just learning and experimenting not worried about security side. I am trying to Update the username and email based on the user id. My table name is users, and the columns within this table are "id,…
charly
  • 183
  • 2
  • 2
  • 11
2
votes
1 answer

Postgres: Optimising concurrent same row updates

THE PROBLEM I'm working with PostgreSQL v10 + golang and have what I believe to be a very common SQL problem: I've a table 'counters', that has a current_value and a max_value integer columns. Strictly, once current_value >= max_value, I would like…
Alechko
  • 1,406
  • 1
  • 13
  • 27
2
votes
1 answer

How to insert a record and return the primary key to update the foreign key in another table?

I need to add value to a foreign key column in a table (table1). For this I have to create a new record in another table (table2) and return the handle to update the column with foreign key in the first table (table1). Also, when I insert the new…
Edu Müller
  • 435
  • 2
  • 5
  • 19
2
votes
1 answer

UPDATING a table in MySQL containing a foreign key column

I am working on 3 tables linked with foreign keys and also set to ON UPDATE CASCADE and ON DELETE CASCADE. These tables are category, subcategory and products. products table - PID(PK), productname, subcatid(FK) subcategory table - subcatid(PK),…
henry
  • 21
  • 1
  • 5
2
votes
2 answers

How do I do an Oracle SQL update from select?

I have created a query for updating a table from another table. The field is updating as expected for a given date. The problem is that for other dates, I am now getting NULL values on the column I updated. How do I set the new value only for the…
JMC
  • 33
  • 1
  • 1
  • 3
2
votes
2 answers

MySQL insert new value when no other like that

I am trying to solve the problem with insert new value into table. Primary key is ID not email... Before insert i need check other records for email value. If no one match inserted email, data is inserted. But i canot write correct code for…
HxAxNxY
  • 43
  • 5
2
votes
1 answer

Do SQL Server updates happen one row at a time?

I was just told that SQL Server updates are executed one row at a time. So if 100 rows were updated, a trigger would also be executed 100 times. Is this accurate? Does this also mean that Inserted pseudo table only holds one row at a time?
AlanPear
  • 737
  • 1
  • 11
  • 32
2
votes
2 answers

Updating Records in Table A based on Records in Table B

I have to write a statement which fills a table (customers) with synthetically generated values. There is an addtional constraint that I should only fill those attributes (columns) with a special property (i.e. formally do a projection on them and…
juniper
  • 311
  • 5
  • 13
2
votes
3 answers

MySQL: Update rows in table by iterating and joining with another one

I have a table papers CREATE TABLE `papers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `my_count` int(11) NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY…
Aufwind
  • 25,310
  • 38
  • 109
  • 154