insert-update

MySQL: Insert data into table, some data comes from another table (relational)

一曲冷凌霜 提交于 2019-12-12 04:56:30
问题 I want to run the following two queries in one: SELECT id FROM user_settings WHERE ...... $id = id_from_query_above(); $value = 100; // this could be anything INSERT INTO user_config (sid, value) VALUES($id, $value) ON DUPLICATE KEY UPDATE value=$value (notice that I want to update if a row associating to the primary key has already been inserted). 回答1: You want the insert . . . select syntax: INSERT INTO user_config(sid, value) SELECT id, $value FROM user_settings WHERE ...... ON DUPLICATE

Update MySQL table column using the sum of a php value stored in an array

半世苍凉 提交于 2019-12-12 02:19:08
问题 I have an html form that users input data into that saves the values in two MySQL tables, invoices and lineitems. When the "save" button is clicked, these values are inserted as a new row in invoices and lineitems. The page refreshes to display the same form, but with the user-inputted values saved in the input fields. The webpage has multiply 'lineitems' the user can create. This data gets saved to the lineitems table. Each invoice row has a unique id that gets added to each lineitem the

PHP MySQLi - insert_id 0 after insert or update - should I read first?

守給你的承諾、 提交于 2019-12-11 20:00:48
问题 I'm still new and some of the right coding practices escape me. Documentation on this particular situation is weak, so I would like to get some advice/suggestions from you experts :) on the following. I have an API that allows users to update 2 tables in one call. One is a SUMMARY table and the other is a DETAIL table with an FK to the SUMMARY table. What I have my code doing is I do an UPSERT (insert/update) to the SUMMARY table, grab the insert_id and then delete the records from the DETAIL

Hibernate @SQLInsert and On Duplicate Key

廉价感情. 提交于 2019-12-11 18:22:21
问题 In Hibernate, you can use @SQLInsert to define a custom insert query. Hibernate is using prepared statements, so you just need to provide the ? as placeholder, like this: INSERT INTO table (colA, colB) VALUES (?,?) On a duplicate key for colA , I want colB to be updated with the new value, so i tried INSERT INTO table (colA, colB) VALUES (?,?) ON DUPLICATE KEY UPDATE colB = ? - This however throws the error that no third parameter is given. ( No value specified for parameter 3 ) How is the

MySql PHP Update Error

寵の児 提交于 2019-12-11 15:33:15
问题 I've been messing about with this code for a few hours now and can't work out why it's not working. It's a profile update php page that is passed through JQuery and all seems to be fine except for it actually updating into the table. Here is the code I'm using: session_start(); include("db-connect.php");//Contains $con $get_user_sql = "SELECT * FROM members WHERE username = '$user_username'"; $get_user_res = mysqli_query($con, $get_user_sql); while($user = mysqli_fetch_array($get_user_res)){

SSIS OLEDB Command transformation (Insert if not exists)

狂风中的少年 提交于 2019-12-11 11:59:27
问题 Ok so according to Microsoft docs the OLE DB Command Transformation in SSIS does this The OLE DB Command transformation runs an SQL statement for each row in a data flow. For example, you can run an SQL statement that inserts, updates, or deletes rows in a database table. So I want to write some SQL to Insert rows in one of my tables only IF the record doesn't exists So I tried this but the controls keeps complaining of bad sintaxys IF NOT EXISTS (SELECT * FROM M_Employee_Login WHERE Column1=

MongoDB update a document when exists already with ReactiveMongo

女生的网名这么多〃 提交于 2019-12-11 11:27:56
问题 I'm writing a Scala web application that use MongoDB as database and ReactiveMongo as driver. I've a collection named recommendation.correlation in which I saved the correlation between a product and a category. A document has the following form: { "_id" : ObjectId("544f76ea4b7f7e3f6e2db224"), "category" : "c1", "attribute" : "c3:p1", "value" : { "average" : 0, "weight" : 3 } } Now I'm writing a method as following: def calculateCorrelation: Future[Boolean] = { def calculate(category: String,

MongoDB: cannot upsert if query object and update object contain a same property , 'Cannot apply $addToSet modifier to non-array'

一笑奈何 提交于 2019-12-11 10:39:26
问题 I want to execute a complex upsert, made by the following elements: query on a field f by regex update of the same field f (that is specified in the query object too) Like this: db.coll.update({ prop: /valueprop/i } , { $addToSet:{ prop:'a value' } } , true, false) My expectation would be that if the document does not exist in the collection it is inserted with prop field equals to 'a value'; in other words it should insert a document with value of prop field that is the one specified in the

Insert Data if not exists (from 2 tables) and Update otherwise

邮差的信 提交于 2019-12-11 01:45:59
问题 Good day. I have 3 tables: tblWarehouseProducts : ProductID ProductName ProductCode Quantity tblBranchProducts : ProductID ProductCode ProductCode Quantity Location tblStockMoves : ProductID DestinationLocation Quantity ReferenceNumber Basically, the process is that Branch X requests a product from Warehouse Y. Warehouse Y then creates a request order(called a Stock Move ) and stores the request in tblStockMove . Say for this case, we have a Stock Move with Reference Number XYZ: REFERENCE NO.

MongoDB Number Field will not insert or update with the number that I input

ぃ、小莉子 提交于 2019-12-10 23:16:52
问题 this is my problem: db.Group6391102Bounds.insert({ bound:"latest",id:138548488276343678,complete:false}) db.Group6391102Bounds.find() { "_id" : ObjectId("5297d9e5ef9f659b82271617"), "bound" : "earliest", "id" : 138548488276343680, "complete" : false } { "_id" : ObjectId("5297dc28b2d702ea878b540d"), "bound" : "latest", "id" : 138548488276343680, "complete" : false } db.Group6391102Bounds.insert({ bound:"middle",id:138548488276343678,complete:false}) db.Group6391102Bounds.find() { "_id" :