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
18
votes
7 answers

Multiple SQL Update Statements in single query

I am in a situation where I am having to update about 12,000 items in my DB. Each row needs to mirror an excel file that I made previously. I have made the file that creates each line of SQL statement, but I am not sure if I can run each line in a…
Erick Ely
  • 269
  • 1
  • 7
  • 16
18
votes
3 answers

MySQL CASE...WHERE...THEN statements

I have a MySQL UPDATE statement that uses a CASE clause UPDATE partsList SET quantity = CASE WHEN partFK = 1 THEN 4 WHEN partFK = 2 THEN 8 END WHERE buildFK = 1; The above statement works. Yet when I remove one of the WHEN statements, it…
CDspace
  • 2,639
  • 18
  • 30
  • 36
18
votes
4 answers

PHP: Update multiple MySQL fields in single query

I am basically just trying to update multiple values in my table. What would be the best way to go about this? Here is the current code: $postsPerPage = $_POST['postsPerPage']; $style = $_POST['style']; mysql_connect ("localhost", "user", "pass")…
Chris
  • 461
  • 3
  • 9
  • 16
18
votes
6 answers

How do I generate a unique, random string for one of my MySql table columns?

I’m using MySql 5.5.37. I have a table with the following columns +------------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra…
Dave
  • 15,639
  • 133
  • 442
  • 830
18
votes
6 answers

MySQL update statement to store ranking positions

I'm trying to get my head around a query and I just can't figure it out. I would appreciate if someone give me a pointer. As a simple example of what I'm trying to achieve, I have these records in the database Score|Ranking ------------- 100 |0 200…
user385762
  • 581
  • 2
  • 6
  • 16
18
votes
3 answers

How to increment value in postgres update statement on JSON key

When updating a relational table: CREATE TABLE foo ( id serial primary key, credit numeric); UPDATE foo SET bar = bar + $1 WHERE id = $2; However the equivalent in JSON doesn't work: CREATE TABLE foo ( id serial primary key, data json); UPDATE foo…
bguiz
  • 27,371
  • 47
  • 154
  • 243
18
votes
2 answers

MySQL - SELECT then UPDATE

I have a script written in PHP which has this line which is working correctly for selecting the data i need; $result = mysql_query("SELECT product_name, sku, qty FROM supplier_dropship_items WHERE supplier_id = '3' AND status = '2'", $db_beb); What…
TheWebsiteGuy
  • 304
  • 1
  • 2
  • 12
18
votes
6 answers

Update Field When Not Null

I have an update statement that updates fields x, y and z where id = xx. In the table I have a few different x_created_datetime fields (for different portions of the record that are maintained/entered by different folks). I'd like to write a single…
Cory Dee
  • 2,858
  • 6
  • 40
  • 55
18
votes
2 answers

PyMysql UPDATE query

I've been trying using PyMysql and so far everything i did worked (Select/insert) but when i try to update it just doesn't work, no errors no nothing, just doesn't do anything. import pymysql connection = pymysql.connect(...) cursor =…
Shay
  • 1,375
  • 5
  • 16
  • 26
18
votes
1 answer

ORA-01779: cannot modify a column which maps to a non key-preserved table

I have this procedure: create or replace procedure changePermissionsToRead( datasource in varchar2 ) IS begin update ( select * from WEB_USERROLE ur , WEB_USERDATASOURCE ds where ur.username = ds.username and ds.datasource =…
FrankTan
  • 1,626
  • 6
  • 28
  • 63
18
votes
2 answers

Error (Error Code: 1175) during executing update command on table using MySQL Workbench 5.2

I'm using MySQL Server5.5 in which MySQL Workbench 5.2 CE is included. I'm using MySQL Workbench 5.2 . I have a table named user in DB. I executed the following command on SQL Editor at MySQL Workbench: UPDATE user SET email = 'abc@yahoo.com' WHERE…
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
18
votes
3 answers

Updating a column with the results of a query in PostgreSQL

I have the following table in PostgreSQL 9.2 which contains time stamps: gid [PK] (bigserial), timestamp_mes (timestamp without time zone), time_diff (interval) 1, 2012-01-23 11:03:40, empty 2, 2012-01-23 11:03:42, empty 3, 2012-01-23 11:03:44,…
jatobat
  • 749
  • 3
  • 8
  • 21
18
votes
6 answers

UPDATE syntax in SQLite

I need to know if I can do this in an UPDATE statement: UPDATE users SET ('field1', 'field2', 'field3') VALUES ('value1', 'value2', 'value3'); Or similar syntax. I'm using SQLite. Note: Nobody understands me, I just want to know if it is possible…
calbertts
  • 1,513
  • 2
  • 15
  • 34
18
votes
2 answers

Update top N values using PostgreSQL

I want to update the top 10 values of a column in table. I have three columns; id, account and accountrank. To get the top 10 values I can use the following: SELECT * FROM accountrecords ORDER BY account DESC LIMIT 10; What I would like to do…
djq
  • 14,810
  • 45
  • 122
  • 157
17
votes
3 answers

Oracle - update join - non key-preserved table

I'm trying to replicate an Ingres "update tbl1 from tbl2" command, which doesn't exactly exist in Oracle. So I use "update (select tbl1 join tbl2...)" command. Both tables have primary keys defined and I thought that my join was uniquely…
Jim Kiley
  • 3,632
  • 3
  • 26
  • 43