Linked Questions
26 questions linked to/from How to do an update + join in PostgreSQL?
0 votes
1 answer
1k views
Postgresql Update with subquery [duplicate]
UPDATE Customer C SET name = B.name, age = B.age FROM (SELECT A.*, B.* FROM CUSTOMER_TEMP WHERE A.ID = B.ID) AS B I got a sql as above, after I run the query, it update all my rows to the same result....
0 votes
0 answers
47 views
Error FROM Clause on update sql (postgres) [duplicate]
UPDATE A,B SET A.a = 'something' WHERE A.b = B.b AND A.c = B.C; I have this code inside a function in sql, but it doesn't work. I fill table B inside the function but first of all when I want to use ...
1698 votes
18 answers
2.4m views
How can I do an UPDATE statement with JOIN in SQL Server?
I need to update this table in SQL Server with data from its 'parent' table, see below: Table: sale id (int) udid (int) assid (int) Table: ud id (int) assid (int) sale.assid contains the correct ...
1570 votes
14 answers
1.9m views
How to join (merge) data frames (inner, outer, left, right)
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama&...
59 votes
5 answers
19k views
Django F expressions joined field
So I am trying to update my model by running the following: FooBar.objects.filter(something=True).update(foobar=F('foo__bar')) but I get the following error: FieldError: Joined field references are ...
7 votes
1 answer
6k views
update query from select statement only update if the field is empty
I am trying to write a sql statement to update a column of a table from another tables column. But I only want to update the column if its empty. For example: UPDATE Table SET Table.col1 = ...
1 vote
1 answer
2k views
Postgres: Update a filtered set of rows with a Join
I am trying to update a set of rows which needs to be filtered by a JOIN to another table but which will not be doing the actual update. Example: The table to be update is called t2 It has a master ...
0 votes
1 answer
2k views
Update a table when join with other table using Case in Postgresql
I have 2 tables wherein I need the result as follows : If the country name is 'United States' then the region should be hardcoded as 'Mexico' & if the country name is 'Taiwan' then the region ...
0 votes
1 answer
896 views
Update from join returning id from other table in Postgres
I can't figure out how to do this in Postgres. I have two tables, foo and bar: foo:id, number bar:id, foo_id There is an entry in bar that corresponds to and entry in foo. I want to update foo and ...
0 votes
4 answers
185 views
Update the same data on many specific rows
I want to update multiple rows. I have a lot of ids that specify which row to update (around 12k ids). What would be the best way to achieve this? I know I could do UPDATE table SET col="value" ...
0 votes
0 answers
478 views
PostgreSQL query to map one table's id to another table with many to one criteria
I am trying to map a contributor_id in my archive table to a contributor_id in my sales table. The archive table has 120k entries and the sales table has 20k. The sales table has an '...
0 votes
1 answer
329 views
Postgres SQL script with loop
I need to write a Postgres script to loop over all the rows I have in a particular table, get the date column in that row, find all rows in a different table that have that date and assign that row ...
0 votes
1 answer
395 views
Liquibase: postgres fails, mysql - ok
A pretty simple Spring application made to run using different DataSources. In it I have a liquibase change-set which involves this sql: <sql> UPDATE home_description hd INNER JOIN home h ...
1 vote
1 answer
288 views
PostgreSQL Update Where And
My problem is I got 2 table 1 is coach and 1 is tool coach (cid, forename, surname, toolNo ) tool (toolNo , registNo ) I want to change the coach "Will Smith" 's toolNo to 10 by using the registNo. ...
0 votes
2 answers
158 views
how to not update all rows and only restrict to the where clause
I have an update query in postgres as such: update table1 e set (col1,col2) = (select col1,col2 from table2 se where e.id = se.id and se.col2 is not null); However this updates all rows even the ...