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

How to update a database table letting two fields be empty/not filled/null

On a blog I'm coding I want admins to be able to edit a comment. This works just fine, but there's a problem with writing a new comment because of two fields in the table that should be empty then. The Db-table comments is build up like…
ofmiceandmoon
  • 548
  • 2
  • 9
  • 30
2
votes
1 answer

Can i give permission to a user to alter a table with his data only?

I have a certain user and i want to grant him permissions to alter tables, but only tables with his data, for example the user can change his profile data, but only his data. what i mean by this is altering the rows with his id on it. grant update…
2
votes
2 answers

Oracle (11.2.0.1) : How to identify the row which is currently updated by the UPDATE statement

My table contains around 1 Billion Records. My UPDATE statement took more time to update the huge volume of records. Is there any Oracle view to check how many rows are updated currently?
Rajesh
  • 45
  • 4
2
votes
2 answers

How to fix 'missing FROM-clause entry for table'?

I have a function with query. If condition is true, I update a row with new values. I do a query: SELECT * FROM transfer_flight(41313, '2017-08-15 20:00:00+05'); and I get an error: ERROR: missing FROM-clause entry for table "flights" LINE 1:…
Jack
  • 514
  • 3
  • 11
  • 30
2
votes
1 answer

Updating column in table with sum of another table

I'm relatively new to SQL and have been unable to solve the following issue. In brief, I have two tables. We can call the first table people: name -------- Margaret Jim Lola The second is a list of expenses of different types associated with the…
jgaeb
  • 197
  • 8
2
votes
3 answers

set current_timestamp only on inserting a new row

column date is timestamp - default value - CURRENT_TIMESTAMP I choose this because want a current datetime on inserting a new row. But is is changed each time when another column is updated. Is there a way to keep current_timestamp only on…
qadenza
  • 9,025
  • 18
  • 73
  • 126
2
votes
1 answer

Best practice on sql update statement on NCI dateKey in large Fact table

I have a 55Gb Fact table where I have to delete some records which later on can be reverted back. Number of deleted records vary between 10 to 100 thousand. Currently my delete strategy is based on this: I update the dateKey for the records to be…
BumbleBee
  • 129
  • 9
2
votes
2 answers

Like is not working as expected in update query of join condition

Code : UPDATE elections_ls_2014_stats e JOIN `pc-details` p ON ( e.name LIKE CONCAT('%' ,p.candidate_name ,'%') ) SET e.pc_details_id = p.id WHERE p.year = '2014' AND p.`candidate_results_position` ='1' AND e.pc_details_id IS…
sradha
  • 2,216
  • 1
  • 28
  • 48
2
votes
2 answers

Update statement gives wrong result with subquery

I have the following query which gives no error when I used a non-existent column reference in the subquery. The column which I referred in the subquery is actually a column in the table being updated. create table tbl1 (f1 bigint, f2 char(10), f3…
2
votes
3 answers

How to update multiple rows in a table?

I have to update the table daytot with the values present in the array named $result3. How could this be done? $this->db->select('tdate'); $this->db->where('tdate >=', $newDate); $this->db->where('tdate <=',…
2
votes
1 answer

Mysql "like"-query gets no results, but it should

I have a table like this: jobunique | jobtitle | joblat | joblng 1 | kellner | 20 | 40 In phpMyAdmin I tried to make this query: SELECT jobunique, joblat, joblng FROM job WHERE jobtitle LIKE '%kell%' But the query gives me no…
2
votes
2 answers

how to update one record column to true, all else false

I am trying to update a column in a record to true to indicate that the record is the one active in the table. However, by updating this record, I must then update all other records for that column to false. Is there a way to do this in one SQL…
nikotromus
  • 1,015
  • 16
  • 36
2
votes
2 answers

Big query update struct to null in repeated field

In Google bigquery, I'm trying to do an update on a repeated field. For comparison, this works (or at least is flagged as valid), but of course isn't actually updating the field. UPDATE my.table t SET my_field = ARRAY( SELECT AS STRUCT g.foo,…
2
votes
1 answer

Merge into Table1 using table2, table3 on (multiple conditions)? Missing syntax

I have table1, table2 and table3, they have a join condition that relates between them. suppose it is the (ID) column. So the question is, in the case of using the merge statement, is it possible to construct the syntax to be like this: Merge into…
2
votes
2 answers

How to update a table joined with another table multiple times in Oracle?

I have three fields in my table and I want to update them by joining three times to another table. I know that I have to use merge into, but I couldn't find any similar query that uses merge into and join with only one table for multiple times. The…
iminiki
  • 2,549
  • 12
  • 35
  • 45