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

Postgres update the table -> change the substring in text[]

I'm working with Python, SQLAlchemy(I don't use the ORM) and Postgres. I have a table in Postgres which includes two text[]fields (to & from), and some others(irrelevant). If a 'from' column includes a substring "priority", then the 'to' column may…
Majmun
  • 19
  • 5
2
votes
3 answers

Date Time Conversion in MySQL

I imported a CSV file into MySQL. The CSV file contains Date/Time in the format 'mm/dd/yyyy hh:mm'. It gets imported into MySQL only as text. So I did import it as text. I then created another field hoping to convert this text value to date time in…
stat77
  • 123
  • 1
  • 8
2
votes
2 answers

Set Duplicate Values to Null in PostgresSQL retaining one of the values

I have a database like this: id name email 0 Bill bill@fakeemail.com 1 John john@fakeemail.com 2 Susan susan@fakeemail.com 3 Susan J susan@fakeemail.com I want to remove duplicate emails by setting the value to null,…
Jordash
  • 2,926
  • 8
  • 38
  • 77
2
votes
1 answer

Updating a table to increment a value per user id

I have the following table (called node_items): id node_id position == ======= ======== 1 1 1 2 1 1 3 2 1 4 2 1 5 2 1 6 2 1 7 3 1 8 3 1 9 3 1 10 …
kojow7
  • 10,308
  • 17
  • 80
  • 135
2
votes
2 answers

Update referencing on subquery (sqlite)

I have a table with md5 sums for files and use the following query to find the files which exist in one hashing-run and not in the other (oldt vs newt): SELECT * FROM md5_sums as oldt WHERE NOT EXISTS (SELECT * FROM md5_sums as…
Egirus Ornila
  • 1,234
  • 4
  • 14
  • 39
2
votes
1 answer

How to run SQL Update query in NiFi PUTSQL?

I want to update a column enum_value of tableB with the values of another column enum_value in tableA using MySQL update query as follows: UPDATE tableB t1 INNER JOIN TableA t2 ON t1.sig_name = t2.sig_name SET t1.enum_value = t2.enum_value WHERE…
Shrads
  • 883
  • 19
  • 39
2
votes
1 answer

Using UPDATE FROM to mass-set a field

I have the following query that I've used to pull out a vehicle ID, it's registration, a driver id and the driver's name. The _core_people table you see referenced in this query also a field I wish to set to the vehicle's plate. Here's the…
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
2
votes
2 answers

How to speed up copy_expert in postgresql?

The following function imports around 60k records in 111 seconds. I've heard others say that copy_from and copy_expert are doing 1 million records in less than a minute. Is there something about using copy_expert that is slowing down process vs…
Casey
  • 2,611
  • 6
  • 34
  • 60
2
votes
7 answers

Adding a constraint to prevent duplicates in SQL Update Trigger

We have a user table, every user has an unique email and username. We try to do this within our code but we want to be sure users are never inserted (or updated) in the database with the same username of email. I've added a BEFORE INSERT Trigger…
user29964
  • 15,740
  • 21
  • 56
  • 63
2
votes
1 answer

Is there a way to UPDATE TOP (N) with inner join where N is a field of such inner join?

I'm trying to create a script that synchronizes Sales and Inventory tables. For that I wrote an UPDATE on the Inventory table (which has 1 record per item of inventory present) like this: UPDATE TOP (q.QuantitySold) i SET i.Converted = 1, …
2
votes
1 answer

How to update the record's dropdownlist based on precedence?

I have a dropdownlist which contains: Rank1 Rank2 Rank3 Rank4 and update button. I have the following record like id name rank 1 chetan 1 2 ajay 3 3 kelly 2 I want to write update SQL query in such a way that:…
chetan kambli
  • 794
  • 5
  • 21
2
votes
1 answer

How to update an empty jsonb column using jsonb_set in postgresql?

My purpose is to update a jsonb column using jsonb_set, which is currently null, with an object having more than one key-value pairs. The update command executes successfully but it is not updating anything, the column is still coming up empty. I am…
JessePinkman
  • 613
  • 8
  • 15
2
votes
1 answer

How to create an update statement when the field is entered as a variable/parameter

I'm trying to update a table in a database, but every time the button a button is pressed, it should update a different column of the same record. Any ideas on how to do this? The table has columns QuizID (autonumber), QuizName (string), OutOf…
IggyDaDog
  • 53
  • 4
2
votes
1 answer

InnoDB x-locks in READ COMMITTED isolation level

From MySQL glossary: READ COMMITTED When a transaction with this isolation level performs UPDATE ... WHERE or DELETE ... WHERE operations, other transactions might have to wait. The transaction can perform SELECT ... FOR UPDATE, and LOCK IN SHARE…
Croco
  • 326
  • 1
  • 12
2
votes
4 answers

Best way to write PHP SQL Update Statement

I have this PHP SQL statement: $updateCategory = "UPDATE category SET name=".$name.", description=".$description.", parent=".$parent.", active=".$active." WHERE id=".$catID.""; What is…
Chris
  • 21
  • 1
  • 2