sql-update

MySQL CASE…WHERE…THEN statements

我与影子孤独终老i 提交于 2019-12-29 05:22:10
问题 I have a MySQL UPDATE statement that uses a CASE clause UPDATE partsList SET quantity = CASE WHEN partFK = 1 THEN 4 WHEN partFK = 2 THEN 8 END WHERE buildFK = 1; The above statement works. Yet when I remove one of the WHEN statements, it breaks and the error indicates the CASE clause isn't returning anything. Is it that the CASE clause must have more than one WHEN to function. I don't know beforehand how many updates I'll need, so I'm trying to build a single update statement that can handle

Updating listview through fragments

a 夏天 提交于 2019-12-29 01:46:06
问题 here is my problem I have an activity that contains two fragments. Fragment A have a listview and Fragment B is in charge of updating the database now I don't know how to update the datas in listview inside Fragment A right after updating the data in Database from Fragment B. Can you help me and give a sample code for this? Thanks a lot. 回答1: In this example, FragmentA call notify. INotifier public interface INotifier { public void notify(Object data); } Utils public class Utils { public

How to check if an UPDATE mysqli query is correctly executed?

家住魔仙堡 提交于 2019-12-29 01:35:52
问题 Here is my case: $sql = 'UPDATE user SET password = ? WHERE username = ? AND password = ?'; if($stmt->prepare($sql)) { $stmt->bind_param('sss', $newPass, $_SESSION['username'], $oldPass); $stmt->execute(); } Now, how can I see if the UPDATE query is successfully executed? And more precisely how can I see if the old password and username are correct so that I can store the new password? I've tried by doing this: $res = $stmt->execute(); echo 'Result: '.$res; But I always get: Result: 1 even if

Recovery after wrong MySQL update query?

偶尔善良 提交于 2019-12-28 11:59:07
问题 I made a wrong update query in my table. I forgot to make an id field in the WHERE clause. So that updated all my rows. How to recover that? I didn't have a backup.... 回答1: Sorry man, but the chances of restoring an overwritten MySQL database are usually close to zero. Different from deleting a file, overwriting a record actually and physically overwrites the existing data in most cases. To be prepared if anything comes up here, you should stop your MySQL server, and make a copy of the

PHP: Update multiple MySQL fields in single query

核能气质少年 提交于 2019-12-28 05:33:27
问题 I am basically just trying to update multiple values in my table. What would be the best way to go about this? Here is the current code: $postsPerPage = $_POST['postsPerPage']; $style = $_POST['style']; mysql_connect ("localhost", "user", "pass") or die ('Error: ' . mysql_error()); mysql_select_db ("db"); mysql_query("UPDATE settings SET postsPerPage = $postsPerPage WHERE id = '1'") or die(mysql_error()); The other update I want to include is: mysql_query("UPDATE settings SET style = $style

Get count of records affected by INSERT or UPDATE in PostgreSQL

孤者浪人 提交于 2019-12-28 05:30:07
问题 My database driver for PostgreSQL 8/9 does not return a count of records affected when executing INSERT or UPDATE . PostgreSQL offers the non-standard syntax "RETURNING" which seems like a good workaround. But what might be the syntax? The example returns the ID of a record, but I need a count. INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did ; 回答1: I know this question is oooolllllld and my solution is arguably overly complex, but that's my favorite kind of

Replace all fields in MySQL

折月煮酒 提交于 2019-12-28 04:14:09
问题 I need to replace some chars in the columns of a table, by using the REPLACE command. I know that the REPLACE command needs a column name, then the text to change (in the following example, the 'a' char) and the new text (in the following case, the 'e' char). UPDATE my_table SET my_column = REPLACE (my_column,'a','e' ); So that executing this command will change all the ' a ' occurrences in the my_column column of the my_table table with the ' e ' char. But what if i need to execute the

MySQL UPDATE syntax with multiple tables using WHERE clause

血红的双手。 提交于 2019-12-28 03:05:38
问题 Case: How to update table1 with data from table2 where id is equal? Problem: When I run the following update statement, it updates all the records in table1 (even where the id field in table1 does not exist in table2 ). How can I use the the multiple update table syntax, to update ONLY the records in table1 ONLY where the id is present in table2 and equal? UPDATE table1,table2 SET table1.value=table2.value WHERE table2.id=table1.id Thanks in advance. 回答1: here's the correct syntax of UPDATE

Oracle Update Query using Join

喜夏-厌秋 提交于 2019-12-28 02:19:04
问题 I am trying to update the amount using Join but getting exception: UPDATE tab1 SET tab1.total_adjusted_cost = tab1.total_adjusted_cost + t1.total FROM table1 tab1, (SELECT tab3.name, tab3.add, SUM(tab2.amount) AS total FROM table2 tab2, table3 tab3, table4 tab4 WHERE tab2.id = tab3.id AND tab3.id = tab4.id AND tab4.indicator = 'Y' GROUP BY tab3.name, tab3.add ) t1 WHERE tab1.id = t1.id; SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" 回答1:

Use SELECT inside an UPDATE query

我是研究僧i 提交于 2019-12-28 02:06:45
问题 How can I UPDATE a field of a table with the result of a SELECT query in Microsoft Access 2007. Here's the Select Query: SELECT Min(TAX.Tax_Code) AS MinOfTax_Code FROM TAX, FUNCTIONS WHERE (((FUNCTIONS.Func_Pure)<=[Tax_ToPrice]) AND ((FUNCTIONS.Func_Year)=[Tax_Year])) GROUP BY FUNCTIONS.Func_ID; And here's the Update Query: UPDATE FUNCTIONS SET FUNCTIONS.Func_TaxRef = [Result of Select query] 回答1: Well, it looks like Access can't do aggregates in UPDATE queries. But it can do aggregates in