sql-update

Mysql update query tooks too long with magento catalog_product_entity_decimal table

回眸只為那壹抹淺笑 提交于 2019-12-25 05:27:22
问题 I am having problem in update query with magento "catalog_product_entity_decimal" table. I need to update product prices dynamically every one hour and the store has ~50k products right now. So i didnt followed the magento way of product price save to bulk update, instead I followed direct product price update in "catalog_product_entity_decimal" table which is giving results. My query is like this $query = "UPDATE catalog_product_entity_decimal val SET val.value = '$final_rounded_price' WHERE

I need Primary keys of the affected rows to be returned after updating a table in MYSQL.

帅比萌擦擦* 提交于 2019-12-25 05:12:21
问题 I need Primary keys of the affected rows to be returned after updating a MYSQL table using my PHP Code. Is there anyway to achieve this? 回答1: You will need to fetch the primary keys before performing the UPDATE : SELECT primary_key_columns FROM my_table WHERE status = 'O'; UPDATE my_table SET status = 'E' WHERE status = 'O'; However, if you have concurrent connections that might alter my_table between the two statements, it's possible that the results of the keys returned by the first SELECT

How to handle no rows returned in an Oracle update using a common sub-select

江枫思渺然 提交于 2019-12-25 04:51:57
问题 Consider the update: UPDATE table1 SET c1 = NVL(( SELECT d1 FROM table2 WHERE table1.id = table2.id ), 0), c2 = NVL(( SELECT d2 FROM table2 WHERE table1.id = table2.id ), 0) The NVL function handles the case where the sub-select returns no rows. Is there a good way to rewrite this (without repeating the sub-select) using this type of syntax: UPDATE table1 SET (c1,c2) = ( SELECT d1, d2 FROM table2 where table1.id = table2.id ) such that the case where the sub-select returns now rows is handled

How to handle no rows returned in an Oracle update using a common sub-select

浪子不回头ぞ 提交于 2019-12-25 04:51:19
问题 Consider the update: UPDATE table1 SET c1 = NVL(( SELECT d1 FROM table2 WHERE table1.id = table2.id ), 0), c2 = NVL(( SELECT d2 FROM table2 WHERE table1.id = table2.id ), 0) The NVL function handles the case where the sub-select returns no rows. Is there a good way to rewrite this (without repeating the sub-select) using this type of syntax: UPDATE table1 SET (c1,c2) = ( SELECT d1, d2 FROM table2 where table1.id = table2.id ) such that the case where the sub-select returns now rows is handled

sqlite CTE with UPDATE

此生再无相见时 提交于 2019-12-25 04:48:13
问题 I hope this is not a duplicate, I red some posts, but could not figure out how to fix this. I have a table like this CREATE TABLE yo (ad INTEGER PRIMARY KEY, pa INTEGER, pd INTEGER); INSERT INTO yo VALUES (1,1,1),(2,1,3),(3,1,4),(4,3,5),(5,4,2),(6,3,8),(7,1,9),(8,6,7),(9,3,6); .header on .mode column yo select * from yo; ad pa pd ---------- ---------- ---------- 1 1 1 2 1 3 3 1 4 4 3 5 5 4 2 6 3 8 7 1 9 8 6 7 9 3 6 I can create a temp table using CTE to obtain the depth level of col 'pd' like

SQL Server 2008 - Add to string in particular position within name column

微笑、不失礼 提交于 2019-12-25 04:35:20
问题 I have been asked to do a job which is beyond my SQL skills a little and having done some research online, cannot quite find the write solution to be done in SQL Server 2008 and not MySQL. I have a table where I need to update specific names by adding an additional string after a certain point whilst keeping the rest of the string to the right intact. e.g. Current Name = 'Name - Location - 0005' New Name = 'Name (West) - Location - 0005' As you can see I need to add the text (West), I have a

update and select the same table problem in mysql

折月煮酒 提交于 2019-12-25 04:08:32
问题 hi want to run a query like this: UPDATE `stories` SET `position`=(select @i:=@i+1) WHERE `topic` IN (SELECT `topic` FROM `stories` WHERE `newstype`='2' GROUP BY `topic`) but target and destination are the same table and mysql doesn't allow me running it. how can i implement it ? 回答1: you can simulate inner join and update only to first table, like set @pos:=0; update stories a, (select topic, @pos:=@pos+1 as new_position from stories where newstype=2 group by topic ) as b set a.position=b

update and select the same table problem in mysql

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 04:08:14
问题 hi want to run a query like this: UPDATE `stories` SET `position`=(select @i:=@i+1) WHERE `topic` IN (SELECT `topic` FROM `stories` WHERE `newstype`='2' GROUP BY `topic`) but target and destination are the same table and mysql doesn't allow me running it. how can i implement it ? 回答1: you can simulate inner join and update only to first table, like set @pos:=0; update stories a, (select topic, @pos:=@pos+1 as new_position from stories where newstype=2 group by topic ) as b set a.position=b

SQL Update row column with random lookup value

三世轮回 提交于 2019-12-25 03:34:33
问题 I am trying to update a lead table to assign a random person from a lookup table. Here is the generic schema: TableA (header), ID int, name varchar (30) TableB (detail), ID int, fkTableA int, (foreign key to TableA.ID) recordOwner varchar(30) null other detail colums.. TableC (owners), ID int, fkTableA int (foreign key to TableA.ID) name varchar(30) TableA has 10 entries, one for each type of sales lead pool. TableB has thousands of entries for each row in TableA . I want to assign the

room db update multiple rows with @query

左心房为你撑大大i 提交于 2019-12-25 03:29:07
问题 I would like to update multiple rows in a room database. But I don't have the objects - I have only the ids. If I update one row I write something like this to my DAO: @Query("UPDATE items SET place = :new_place WHERE id = :id;") fun updateItemPlace(id:Int, new_place:String) With multiple rows I would need something like this: @Query("UPDATE items SET place = :new_place WHERE id = :ids;") fun updateItemPlaces(ids:List<Int>, new_place:String) OR @Query("UPDATE items SET place = :new_place