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
3 answers

"Must declare the scalar variable" when trying to run UPDATE statement in SQL

Trying to update two tables (City and Location) using two table variables (@NameZip, @NameZip2). The city names have ZipCodes and ZipCodes have Names instead of vice versa. Updates are changing City names and ZipCodes where they were wrongly…
schikkamksu
  • 75
  • 1
  • 12
2
votes
4 answers

Access DB query - need help updating certain records

I have an access DB which we use to track tickets. Each ticket may have multiple occurrences because of different programming changes associated with that ticket. Each record also has a program_type field which is SVR or VB. Example: 123456 - SVR -…
somacore
  • 6,294
  • 3
  • 24
  • 19
2
votes
2 answers

Obtain AVG from December to December SQL

I have this table (example) : http://www.sqlfiddle.com/#!9/412b11/1 and i need to insert the average of the whole year + the last year december in the AnualAmount column based on the year, this is the result that i have to obtain using the example…
xtrios
  • 125
  • 5
  • 11
2
votes
2 answers

MySQL creates new rows instead of updating when using the INSERT INTO SELECT ... ON DUPLICATE KEY UPDATE ... SQL Statement

I run into a problem with this query: INSERT INTO unit_storage (user_id,diagram_id,amount) SELECT uf.user_id, uf.diagram_id, uf.amount FROM unit_factory uf WHERE uf.production_finish_time < /*current unix epoch seconds*/ AND…
Moe Epo
  • 92
  • 9
2
votes
2 answers

PSQL join - Column "table.column" does not exist

I need to update records in a table but only if a certain column of this table equals the content of a column of another table. But first, just to be sure, I want to select all of the records that meets this specific so I've tried something like:…
Leon
  • 665
  • 4
  • 10
  • 32
2
votes
1 answer

Update column in table depending on table data

I am working on a table on SQL where I need to fill in a new column depending on the value of 2 other columns in the table. The rules are: - New column = 1 if Row id = 1 and the group id for that row has more rows with the same group id (See pic) …
Maz
  • 59
  • 9
2
votes
1 answer

UPDATE statement hangs because of locks

I'm ran my .pgsql script using /i blah.pgsql script and then using my .java function to call that pgsql to test it. However, after I ran it. I realized it corrupted my data, and I am not sure how to debug and what's causing the corrupt data. I can't…
2
votes
2 answers

Update Query With Joins and Group by Clause

I have the following query and I'm trying to update table1 with the Total amount. Is there anyway to do this in 1 step? select e.id , p.id , case when count(distinct e.item) = 1 then 100 when count(distinct e.item) = 2…
zSynopsis
  • 4,854
  • 21
  • 69
  • 106
2
votes
1 answer

MySQL Update First Row In Table

I have a table with single column. EmailTable NotifyEmail mom@gmail.com No id no nothing just single row single column. So how do I update this row with new value? I tried: UPDATE NotifyEmail FROM EmailTable SET dad@gmail.com It's not…
GeneCode
  • 7,545
  • 8
  • 50
  • 85
2
votes
2 answers

Update SQL table from VB multiple where condition

I am attempting to update an SQL table from VBA (with the below code)and cant seem to get it correct. I would like to update the columns one, two, three and four based on the search conditions of A, B, C, D, E. What am I getting wrong here? There is…
user6089076
2
votes
1 answer

Update Query with Closest DateTime Matching with Inner Join

I have the following two tables CREATE TABLE Ep ([E] varchar(9), [M] varchar(9), [DTE] DATETIME) ; INSERT INTO Ep ([E], [M], [DTE]) VALUES ('1595861-1', '1595861-1', CONVERT(datetime, '2002-11-26 14:18:00', 20)), ('1595904-1',…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
2
votes
2 answers

updating a single column in an MSSQL table based on multiple conditions

I'm trying to update a table: UPDATE Table_name SET start_date = '12/12/2015' where employee_number = 111111 but I need to modify hundreds of start_dates based on employee_number. UPDATE Table_name SET start_date = '12/12/2015' where…
C0ppert0p
  • 634
  • 2
  • 7
  • 23
2
votes
3 answers

Postgres SQL UPDATE based on result of a previous SELECT

In Postgres 10 I want to perform an UPDATE twice. First UPDATE should run no matter what, updating the alwaysupdate column. And the second UPDATE should run only if the SELECT statement below returns a row count of 0, which means sometimesupdate…
user779159
  • 9,034
  • 14
  • 59
  • 89
2
votes
2 answers

Why does this sub-select work? No FROM clause present

I made a silly mistake while writing a PostgreSQL request. The syntax seems to be completely wrong, however it still half work. I have this table (subscriber): id - device_id - invert 1 'abcd' true 2 'abcd' true There are other…
Laetan
  • 879
  • 9
  • 26
2
votes
3 answers

Composite update statement in SQL

I'm not sure how to do this -- I've got a local table with fields as such that require updating. select column_835 1, column_836 = 6, column_837 = 8, column_838 = 1, column_839 = 6, column_840 = 3, column_841 = 6, …
Elizabeth
  • 719
  • 1
  • 14
  • 27
1 2 3
99
100