sql-update

UPDATE with no subquery throws error: Subquery returns more than 1 row

血红的双手。 提交于 2019-12-20 03:20:59
问题 Can somebody explain to me this... :) (using MySQL 5.6.13) UPDATE offer SET cosid=1 WHERE id=40; Query OK, 1 row affected (0.07 sec) Rows matched: 1 Changed: 1 Warnings: 0 UPDATE offer SET cosid=4 WHERE id=40; ERROR 1242 (21000): Subquery returns more than 1 row UPDATE offer SET cosid=5 WHERE id=40; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 Every valid index is accepted except of four :( This is offer table: CREATE TABLE offer ( id bigint(20) NOT NULL AUTO

Oracle SQL correlated update

a 夏天 提交于 2019-12-20 03:17:20
问题 I got three tables: t1.columns: a,c t2.columns: a,b t3.columns: b,c,d Now what I want is to update t1.c with t3.d. But I can't just update t1 from t3 using t1.c = t3.c I also have to go though t3.b = t2.b and t1.a = t2.a. I've tried something like this: UPDATE table1 t1 SET t1.c = (select t3.d from table2 t2, table3 t3 where t2.b = t3.b and t1.a = t2.a) WHERE EXISTS ( SELECT 1 FROM table2 t2, table3 t3 WHERE t1.c = t3.c and t1.a = t2.a); This code generates error-msg: ORA-01427: single-row

Update certain array elements of a json array in PostgreSQL 9.4

坚强是说给别人听的谎言 提交于 2019-12-19 19:44:00
问题 I have a table like this; CREATE TABLE test ( id BIGSERIAL PRIMARY KEY, data JSONB ); INSERT INTO test(data) VALUES('[1,2,"a",4,"8",6]'); -- id = 1 INSERT INTO test(data) VALUES('[1,2,"b",4,"7",6]'); -- id = 2 How to update element data->1 and data->3 into something else without PL/* ? 回答1: You cannot manipulate selected elements of a json / jsonb type directly. Functionality for that is still missing in Postgres 9.4 (see @Craig's comment). You have to do 3 steps: Unnest / decompose the JSON

Knex.js - How To Update a Field With An Expression

依然范特西╮ 提交于 2019-12-19 19:39:11
问题 How do we get Knex to create the following SQL statement: UPDATE item SET qtyonhand = qtyonhand + 1 WHERE rowid = 8 We're currently using the following code: knex('item') .transacting(trx) .update({qtyonhand: 10}) .where('rowid', 8) However, in order for our inventory application to work in a multi-user environment we need the qtyonhand value to add or subtract with what's actually in the database at that moment rather than passing a value that may be stale by the time the update statement is

“Build” a prepared SQL statement based on user-inputs with PHP

浪尽此生 提交于 2019-12-19 11:53:50
问题 This question is a bit hard to phrase, but basically I have a form. It's an account information form where a person can change the information associated with their account. The catch is that the entire form gets submitted with each input being optional (Leave input empty for no-change) . So for example with this form you can change your city, address, and phone. However a person can choose to only fill out city, press submit and just that info gets updated, all other info remains the same.

How to update DB2 table with a join?

一曲冷凌霜 提交于 2019-12-19 11:32:11
问题 I have two tables and I want to update by joining them. I am using DB2 V9.7. ORDER_APPROVALS ORDER_ID CREATED_BY_ID CREATED_BY_NAME PROCESS_DT ------------------------------------------------------- 234 2 admin (null) 307 2 admin (null) 313 2 admin 11-11-2013 ORDER_ATTRIBUTE ORDER_ID ATTRIBUTE_ID VALUE ----------------------------------- 234 123 ? --(ORDER_APPROVALS.CREATED_BY_NAME) 307 123 ? --(ORDER_APPROVALS.CREATED_BY_NAME) I want to update value field against Attribute_ID 123. So far I

How to properly use XML parameter for Update procedure in SQL Server

我的梦境 提交于 2019-12-19 10:45:24
问题 I am pretty new to XML and am looking for a way to use XML from an input parameter for the below part of a stored procedure (using SQL Server 2012). The XML is submitted via JS / Ajax and looks like this: var xmlMain = '<root><title>' + title + '</title><summary>' + summary + '</summary><post>' + post + '</post><departmentID>' + departmentID + '</departmentID></root>'; The parameter in SQL is defined as: @xmlMain xml To select from the XML the following works: SELECT [Xml_Tab].[Cols].value('

Multiple success messages from SQL Server Update statement

半城伤御伤魂 提交于 2019-12-19 10:33:49
问题 I have the following query that SHOULD update 716 records: USE db1 GO UPDATE SAMP SET flag1 = 'F', flag2 = 'F' FROM samp INNER JOIN result ON samp.samp_num = result.samp_num WHERE result.status != 'X' AND result.name = 'compound' AND result.alias = '1313' AND sample.standard = 'F' AND sample.flag2 = 'T'; However, when this query is run on a SQL Server 2005 database from a query window in SSMS, I get the following THREE messages: 716 row(s) affected 10814 row(s) affected 716 row(s) affected So

Multiple success messages from SQL Server Update statement

跟風遠走 提交于 2019-12-19 10:33:29
问题 I have the following query that SHOULD update 716 records: USE db1 GO UPDATE SAMP SET flag1 = 'F', flag2 = 'F' FROM samp INNER JOIN result ON samp.samp_num = result.samp_num WHERE result.status != 'X' AND result.name = 'compound' AND result.alias = '1313' AND sample.standard = 'F' AND sample.flag2 = 'T'; However, when this query is run on a SQL Server 2005 database from a query window in SSMS, I get the following THREE messages: 716 row(s) affected 10814 row(s) affected 716 row(s) affected So

Updating gridview with SqlDataSource in asp.net

对着背影说爱祢 提交于 2019-12-19 10:25:12
问题 i want to update the records from the gridview using SqlDataSource , here is what i am doing. below is my gridview markup <asp:GridView ID="grdManageFaculties" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="LocalServerDataSource" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" Width="100%" OnRowUpdating="grdManageFaculties_RowUpdating"> <Columns> <asp:TemplateField HeaderText="MANAGE"> <ItemTemplate> <asp:LinkButton ID="lnkEdit" runat="server"