sql-update

Update multiple tables in a single query in mysql

北城以北 提交于 2019-12-24 03:20:03
问题 I have three query and I would like to have a single one. These is my query: UPDATE tab1 SET a='' WHERE id=3; UPDATE tab2 SET b='' WHERE id=9; UPDATE tab3 SET c='' WHERE id=5; 回答1: You can try below code: UPDATE tab1, tab2, tab3 SET tab1.a = '', tab2.b = '',tab3.c = '' WHERE tab1.id = 3 AND tab2.id = 9 AND tab3.id = 5; UPDATE: As per mentioned by OP, the code not working for Mysql 5.5 , below code added UPDATE tab1 a INNER JOIN tab2 b ON (a.id = b.id) INNER JOIN tab3 c ON (a.id = c.id) SET

SQL timestamp does not change when UPDATE happens

[亡魂溺海] 提交于 2019-12-24 03:16:48
问题 I use the following SQL command to create a products table on an Android client. CREATE TABLE IF NOT EXISTS 'products' ( '_id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name' TEXT, 'serverId' INTEGER, 'modifiedAt' TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE ( 'serverId' ) ON CONFLICT REPLACE ); When I load data from a server and insert it into the local database, I use the following commands in the content provider to either update a row or insert new values. public int bulkInsert(Uri uri,

SQL timestamp does not change when UPDATE happens

我的梦境 提交于 2019-12-24 03:16:06
问题 I use the following SQL command to create a products table on an Android client. CREATE TABLE IF NOT EXISTS 'products' ( '_id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name' TEXT, 'serverId' INTEGER, 'modifiedAt' TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE ( 'serverId' ) ON CONFLICT REPLACE ); When I load data from a server and insert it into the local database, I use the following commands in the content provider to either update a row or insert new values. public int bulkInsert(Uri uri,

Eloquent ORM - update and delete not working

不打扰是莪最后的温柔 提交于 2019-12-24 03:15:25
问题 I am working on CRUD for my first Laravel project. Displaying and showing items is working fine. I tried to update the entry with Query to confirm that I can change values in the table and it worked: DB::update("UPDATE seasons SET title = 'foo' WHERE ID = 1"); My Problem is that neither updating nor deleting entries will work. <?php class SeasonAdminController extends \BaseController { // WORKS public function store() { $season = new Season; $season->title = Input::get('title'); $season->save

MySQL: Update rows in table by iterating and joining with another one

我们两清 提交于 2019-12-24 02:49:07
问题 I have a table papers CREATE TABLE `papers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `my_count` int(11) NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `title_fulltext` (`title`), ) ENGINE=MyISAM AUTO_INCREMENT=1617432 DEFAULT CHARSET=utf8 COLLATE=utf8_bin and another table link_table CREATE TABLE `auth2paper2loc` ( `auth_id` int(11) NOT NULL, `paper_id` int(11) NOT NULL, `loc_id` int(11) DEFAULT NULL ) ENGINE=MyISAM

updating existing records with a unique integer

核能气质少年 提交于 2019-12-24 01:47:47
问题 I have an existing table with records in it and I've just added a new column ver which I would like to be unique. create table foo ( bar text, ver integer ); select * from foo; bar ver --- --- one null two null three null I'm struggling with how to do this for some reason. I want to do something like: update foo set ver = ( select generate_series(1, 1000) ); or maybe update foo set ver = v from (select generate_series(1, 1000) as v ); ...but of course neither of those work. Can anyone point

Oracle “Cannot update to NULL”

匆匆过客 提交于 2019-12-24 00:59:57
问题 I have this query on Oracle 10g: UPDATE "SCHEMA1"."CELLS_GLIST" SET ("GLIST_VALUE_ID", "USER_ID", "SESSION_ID") = ( SELECT "GLIST_VALUE_ID", 1 AS "USER_ID", 123456 AS "SESSION_ID" FROM "SCHEMA1"."GLISTS_VALUES_UOR" WHERE ("UOR_ID"=3) AND ("GLIST_ID"=67) AND ("GLIST_VALUE_DESC" = ( SELECT "GLIST_VALUE_DESC" FROM "BMAN_TP1"."GLISTS_VALUES_UOR" WHERE ("UOR_ID"=3) AND ("GLIST_VALUE_ID"="CELLS_GLIST"."GLIST_VALUE_ID") )) ) WHERE EXISTS (......) It keeps saying ORA-01407: cannot update ("SCHEMA1".

MYSQL: Update value from Query

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:46:53
问题 I've got a query: SELECT a.id, b.products_id,a.zenid FROM titles a, ANOTHERDATABASE.products_description b WHERE b.products_name = a.title It gives id products_id zenid 57 3193 0 81 2037 0 What i really need is to update zendid with products_id so it becomes: id products_id zenid 57 3193 3193 81 2037 2037 回答1: This is how you are updating a table using a join in MySQL: UPDATE titles a INNER JOIN ANOTHERDATABASE.products_description b ON b.products_name = a.title SET a.zenid = b.products_id

Why is my JDBC prepared statement update not updating the database?

六眼飞鱼酱① 提交于 2019-12-24 00:22:30
问题 I am using JDBC to update a row in my MySQL database: pConnection.setAutoCommit(true); PreparedStatement pstmt = pConnection.prepareStatement("update mg_build_queue " + // "set buildsetid=?,locale=?,areacode=?,distversionid=?,platformid=?,version=?," + // "priority=?,buildstatus=?,computername=?,buildoutput=?,started=?,finished=?, packageid=?, lockcounter=0 where buildid=?" // ); pstmt.setInt(1, mBuildSet.getId()); pstmt.setString(2, Locale.localesToString(mLocales, ",")); pstmt.setString(3,

MySQL: “Unknown column in where clause” during Update Statement

萝らか妹 提交于 2019-12-23 23:33:44
问题 UPDATE Recipes RE, ( SELECT SUM((((i.iCaseCost/i.iCaseQty)/i.iUnitSize)/i.iUnitSoldBy)*ri.riQty*ri.riMeasureBy) AS 'RecipeCost' FROM Recipes r INNER JOIN RecipeIngredients ri ON r.rID = ri.rID JOIN Ingredients i ON ri.iID = i.iID WHERE ri.rID = RE.rID ) t SET RE.rYieldCost = t.RecipeCost When executed, I get the following error: "Unknown column 'RE.rID' in 'where clause'". Any ideas? 回答1: Your inner derived query doesn't know anything about columns in the outer query. Try moving the WHERE