Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Is it possible to get a particular updated column name from a record?
if so, please help me. since i am creating a history table to store a updated column and their values from rest of the tables.
Please suggest me a correct way to deal this....
I believe it is not possible.
However, you can create an update trigger which monitors the table's columns and have that trigger insert records in your history table. Hope this helps.
The only way for doing this is Using something like a Log file, in this case you will create a table that will contains the updated columns each time there is an update.
In this way you will be able to get the last record that will contains the table_name and the column_name.
And you can use a query looks like that:
select id, column_name, table_name
from Log_table
order by id desc
limit 1
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Using MySQL, I want to retrieve all rows from a table A where a field contains "EQ" for example, copy them into table B (which has exactly the same field), and then delete them from table A.
I heard about triggers. Is that the right approach?
You need 2 SQL statements. First for inserting the data rows from A to B, and then for deleting those rows from A.
INSERT INTO B
SELECT *
FROM A
WHERE Field LIKE '%EQ%';
DELETE
FROM A
WHERE Field LIKE '%EQ%';
Triggers are a way to automate some activities when some other activity in a separate table happens. If you need to make sure that the above 2 operations should be triggered as soon someone INSERTS/DELETES/UPDATES on some other table, then you can create a trigger for that purpose. But with the simple requirement you gave above without any such dependency, I do not see a need of a trigger here.
If you do have such dependency and need, you have to provide proper requirements with details here.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi I need to update multiple rows in a table so I wrote below query, but it only updates the first row and not the others. Please help.
Query:
String sql = "REPLACE INTO subscriber_metadata (msisdn, have_had_speech_pkg, have_had_sms_pkg, created, changed) values ";
Well REPLACE INTO does the following DELETE + INSERT, what you're looking for is UPDATE, doc over here
REPLACE INTO is nothing more than a mechanical DELETE and INSERT. It can incite mysqld to address deadlocks (See my answer to How I prevent deadlock occurrence in my application?)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table named 'User' and it has an autoincremented field userID.
I want to retrieve that userID in my servlet. There is no such parameter/field referred to on that respective HTML. How can I use that userID in my servlet?
I would say your question is far to broad for a definite answer mate but here goes my best guess.
I assume you run this table and data in mysql since you tagged this as mysql.
you can retrieve the data you wish with the query as below:
SELECT userID FROM User;
Note: If you have more than 1 this will return all of them. If you want to limit this down to 1 you will need to match that to another unique parameter in your table. For example lets say you have a column in User table called "telephone"
the query would be:
SELECT userID FROM User WHERE telephone = '1234567890';
You can then display the result in your html, depending on what language you use to execute this query with.
Hope this helps
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I want to sort records in my table according to the date/time created.
But i don't have any data/time stamp column in my table.
Is there a way in which i can still select records according to the date/time created or modified???
I am using MYSQL.
I tried SELECT * from user ORDER BY created_at but this also not working.
As other commenters have pointed out, the short answer is no. MySQL doesn't allow you to sort by the time at which a record was created unless you have explicitly stored that value in the database. Here's a possible way out for the future:
ALTER TABLE users ADD COLUMN created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE users ADD INDEX created_at (created_at);
Then your future INSERT queries will add a NOW() argument to populate the created_at column.
If you do that, then when you retrieve records, if they have a "created at" value equal to the default, you'll know the record was created before you modified your INSERT query. You could go through and manually update those records, or assign them all today's date for simplicity.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table with one columns of integer data type. I want to add another columns with string data type.
Finally I want to copy the values in first column to the second columns.
That means I want to copy the integer data from column one and copy that to second column in string format.
Casting the column to a CHAR will do what you want:
UPDATE `table` SET column2 = CAST(column1 AS CHAR)
Use ALTER TABLE to add columns. Syntax for adding is
ALTER TABLE tablename ADD column_name datatype;
To transfer:
UPDATE tablename SET second_column = CAST(first_column AS CHAR);