sql-update

How to change a SALT password in a database using PHP?

孤街醉人 提交于 2019-12-24 08:57:04
问题 I am using a HTTP POST from android to some php script in order to update a users password in the database. I am using the same SALT hash as is done when the user creates the account and the database update is running and changing the values of SALT however when I try to log in with the new password it is coming as incorrect. The initial code for creating the password is: public function storeUser($name, $email, $password, $rand) { $uuid = uniqid('', true); $hash = $this->hashSSHA($password);

How can I update a field in one table with a field from another table? (SQL)

拥有回忆 提交于 2019-12-24 08:03:05
问题 Two tables: COURSE_ROSTER - contains COURSE_ID as foreign key to COURSES USER_ID as field I need to insert into COURSES COURSES - contains COURSE_ID as primary key INSTRUCTOR_ID as field that needs to be updated with USER_ID field from COURSE_ROSTER What would the UPDATE sql syntax be? I am trying this, but no good... I'm missing something and I can't find it online. UPDATE COURSES SET COURSES.INSTRUCTOR_ID = COURSE_ROSTER.USER_ID WHERE COURSE_ROSTER.COURSE_ID = COURSES.COURSE_ID 回答1: Not all

Postgres RETURNING clause with join and order

谁说胖子不能爱 提交于 2019-12-24 07:50:03
问题 I've got this query that updates some rows and returns the updated rows in the RETURNING clause. However, even though I've specified ORDER BY mycolumn in the inner query, the rows returned by RETURNING aren't ordered. UPDATE mytable SET status = 'A' FROM ( SELECT id FROM mytable WHERE status = 'B' ORDER BY mycolumn LIMIT 100 FOR UPDATE ) sub JOIN jointable j ON j.id = sub.id WHERE mytable.id = sub.id RETURNING * I tried putting an ORDER BY in the outer query, like after the JOIN or after the

How to use MERGE or Upsert Sql statement

醉酒当歌 提交于 2019-12-24 07:16:34
问题 How can i use MERGE Sql Statement or UPDATE statement for my below code. I am having a columnName called MachineName , other column values change but MachineName doesnot change. If the Column MachineName changes i need to insert the new values in a secondrow. If not i need to Update the same row. How can i do this. Is it a right approach ? Please help MERGE INTO [devLaserViso].[dbo].[Machine] WITH (HOLDLOCK) USING [devLaserViso].[dbo].[Machine] ON (MachineName = MachineName) WHEN MATCHED THEN

Can I have an inner SELECT inside of an SQL UPDATE?

故事扮演 提交于 2019-12-24 06:49:06
问题 I have a database like where: Table foo has columns id and name Table bar has columns id and foo_id I have an incoming HTTP query with a foo.name , I'd like to insert a row into bar with bar.foo_id set appropriately. So, for example: > SELECT * FROM foo; id name ------ ------- 1 "Andrey" (1 row) > SELECT * FROM bar; (0 rows) Given "Andrey" , is there a single query I can execute to get: > SELECT * FROM bar; id foo_id ------ ------- 1 1 (1 row) I was thinking along the lines of: > UPDATE bar

Can I update/select from a table in one query?

天涯浪子 提交于 2019-12-24 05:35:31
问题 I need to select data when a page is viewed and update the 'views' column is there a way to do this in one query, or do I have to use to distinct queries? 回答1: If you do not want/need to use a transaction, you could create a stored procedure that first updates the view count and then selects the values and return them to the user. 回答2: You would have to do this in two statements in one transaction Begin Tran Update Pages Set Views = Views + 1 Where ID = @ID Select Columns From Pages Where ID

Update column with certain value to a column value with same id

我只是一个虾纸丫 提交于 2019-12-24 04:36:12
问题 My Table: ID | Number ------------------- | 1 | 0x | 1 | 12345678 | 1 | 12345678 | 2 | 0x | 2 | 0x | 2 | 242424 | 3 | 88888 | 3 | 88888 | 4 | 0x | 4 | 0x Table must be updated so that every '0x' will be updated to a correct 'Number' if there exists one. Result needed: ID | Number ------------------- | 1 | 12345678 <-- Updated | 1 | 12345678 | 1 | 12345678 | 2 | 242424 <-- Updated | 2 | 242424 <-- Updated | 2 | 242424 | 3 | 88888 <- No change on id = 3 | 3 | 88888 <- No change on id = 3 | 4 |

Update multiple rows without looping

谁说我不能喝 提交于 2019-12-24 04:26:09
问题 I want to update multiple rows at once in a update statement without using loop. I have the following table with some records as shown below: Table: create table test ( col1 int, col2 int, col3 varchar(20), col4 datetime, name varchar(max) ); Insertion: insert into test values(111,999,'A101','2014-01-01',''); insert into test values(112,998,'A102','2014-01-02',''); insert into test values(113,997,'A103','2014-01-03',''); insert into test values(114,996,'A104','2014-01-04',''); insert into

Updating SQL table from XML

有些话、适合烂在心里 提交于 2019-12-24 04:09:15
问题 I am using InfoPath 2007 to send out a survey (it is not connected to SharePoint or a DataBase). The file I will get back is an XML file. Every place there is an answer block, it has its own unique id (aka field name). Now, I have a SQL Server Database (2007?) with a table "Responses". Its columns are: AnswerID(unique PK), QuestionID (FK) (which is the unique id (field name), and Answer. The QuestionID is already populated with the unique id (field name). There are more than 300 records for

Update multiple tables in a single query in mysql

故事扮演 提交于 2019-12-24 03:21:02
问题 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