sql-update

JAVA JDBC mySql Prepared statement Update query [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-05 07:45:06
问题 This question already has answers here : MySQLSyntaxErrorException near “?” when trying to execute PreparedStatement (2 answers) Closed 1 year ago . I am trying to execute the following code package jdbclesson; import java.sql.*; public class PreparedQuery { public static void main(String[] args) throws Exception { String url = "jdbc:mysql://localhost:3306/alien?useSSL=false"; String uname = "root"; String pass = "ma123"; String query = "UPDATE student SET username= ? where userid= ? ";

PostgreSQL: How to select and update from a table as if it were a queue

假如想象 提交于 2021-01-29 20:51:37
问题 I'd like several processes to pull from a table as if it were a queue. The requirements: Order of the items is important, and must be specified in the query Each process (of which there are an unknown amount) can get chunks of N items at a time Each item must only be processed once I don't want to lock the table (for performance reasons) I have a working solution, but would like some other opinions. First attempt: UPDATE foo SET should_select=0 FROM (SELECT * FROM foo WHERE should_select=1

SQL UPDATE and CASE statement does not work

情到浓时终转凉″ 提交于 2021-01-29 15:09:07
问题 I have the following table "Sales" in MS SQL Server, where [FieldX] is not updated properly: (..[My comment] is of course not an actual column in the table) The reason why the last 3 rows should be = 3, is because I am updating the fields with the following rules: with cte_previous_rows AS ( SELECT Staff_Id, LAG(FieldX) OVER (partition by Staff_Id ORDER by [date]) as Prev_Row FROM Sales ) UPDATE Sales SET FieldX = (CASE WHEN Staff_id_sales < 1500 AND ClosedSale = 0 THEN 0 WHEN Staff_id_sales

Update multiple records in table by using a reference table SQL Server

我是研究僧i 提交于 2021-01-29 11:12:04
问题 I am trying to update a table in SQL by using references from two other tables. I need Table C to be updated with the ID of records from Table A but only where a column from Temp Table B exists in Table A Table A ID ReferenceNumber 1 123 2 321 3 213 4 413 Temp Table B ID ExtractedNum 1 213 2 413 3 321 4 123 Expected Results Table C TableA_ID TableB_ID 3 1 4 2 2 3 1 4 I've tried a few different queries but none of them work the way I need it to: UPDATE table_c SET table_c.tablea_id = a.id --

Convert Oracle SQL query to Azure SQL query

偶尔善良 提交于 2021-01-29 10:02:34
问题 I have a pretty long Oracle SQL query that needs to be compatible for Azure SQL. I am new to both database types. Here is query: MERGE INTO studies USING dual ON (study_id = :study_id) WHEN NOT MATCHED THEN INSERT (study_id, study_date) VALUES (:study_id, :study_date) I am not sure USING dual would work. I read some solution saying that USING dual is not necessary in SQL Server. I really appreciate if you can explain what this query means and how I can translate this for Azure SQL query. 回答1:

How to update multiple rows in a temp table with multiple values from another table using only one ID common between them?

筅森魡賤 提交于 2021-01-29 07:00:22
问题 I am trying to reconcile the IDs in a temp table (top) from another DB table (bottom). Since I only have one ID that's common between the two, I am only getting the top result for all the rows (ReconGlobalRemunerationGrantID) in my temp table. I am aiming to get each of the unique ID and update my temp table as such. Right now, my update query is simple and I update using the ID common between the 2 tables. Is there a function or another command statement I can use to get the result intended?

MySQL 5.7 prepared statements updating the wrong timestamp column

Deadly 提交于 2021-01-29 06:30:40
问题 I'm having some issues with an update on table, when used with a prepared statement. Seems like mysql is updateing a wrong column which was not even specifed in the update command. prepare: drop table test1; create table test1( id int not null, show_from timestamp not null, updated_at timestamp NULL DEFAULT NULL ); insert into test1(id, show_from, updated_at) values(1, '2018-01-11 12:10:11.19808', '2019-04-15 11:50:00.704748'); do this in one batch: UPDATE test1 SET show_from='2018-04-15 11

MySQL 5.7 prepared statements updating the wrong timestamp column

会有一股神秘感。 提交于 2021-01-29 06:25:28
问题 I'm having some issues with an update on table, when used with a prepared statement. Seems like mysql is updateing a wrong column which was not even specifed in the update command. prepare: drop table test1; create table test1( id int not null, show_from timestamp not null, updated_at timestamp NULL DEFAULT NULL ); insert into test1(id, show_from, updated_at) values(1, '2018-01-11 12:10:11.19808', '2019-04-15 11:50:00.704748'); do this in one batch: UPDATE test1 SET show_from='2018-04-15 11

How do I update a table that references duplicate records?

天涯浪子 提交于 2021-01-29 06:17:54
问题 I have two SQL tables. One gets a reference value from another table which stores a list of Modules and their ID. But these descriptions are not unique. I am trying to remove the duplicates of Table A but I'm not sure how to update Table B to only reference the single values. Example: Table A: Table B: -------------------------------- ------------------------------------ ID Description RefID ID Name -------------------------------- ------------------------------------ 1 Test 1 2 1

Trigger multiply from two tables

耗尽温柔 提交于 2021-01-28 19:21:04
问题 i need to create a trigger that multiply two fields from two tables, but i have no idea of how to do it, so let's see if you can help me. Two tables, Products (product_name, price) Orders (product_name (foreign key),units_ordered) I need to add another field on table the Orders that multiply price from Products and units_ordered from Orders, so : total_price = price (from products) X units_ordered (from Orders) Thanks in advance, and sorry for my bad english. Regards 回答1: You don't need