updating table in sql [closed] - mysql

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
I have data from an sql query which i need to update in a table. Im saving the output of this query as a csv file. When i do load this file in sql though using the import export wizard, the data is all jumbled up as the columns have shifted in a lot of cases. So unrelated data is updated in many columns.
What could be the reason for this and please suggest a resolution.
Regards,
Priyesh

The obvious answer here is to use the insert into select syntax. If you have a query already that has generated data, insert it to where you want directly without saving to a CSV.
INSERT INTO target_table
SELECT * FROM your_original_query
If the issue is manually writing out most of the column names for a 150 column table, here is a trick. From within SSMS, click on the Columns folder of the table in question, and drag that to a new query window. You will get a list of all the column names for the table. (You could then remove the few that you do not need.)

Related

Copy rows filtered on a search criteria from one table to another in MySQL [closed]

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.

Howto efficiently search a huge mysql table [closed]

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 6 years ago.
Improve this question
if I had a mysql table that has, lets say 300 million rows, how would I search for a row using
SELECT id WHERE coloumn = "abc" ;
most efficiently? Can I prepare the data so it would help the sql searching through the data? Or does it parse the rows row by row?
The SQL 101 answer here is an index using CREATE INDEX:
CREATE INDEX column_index ON table_name (`column_name`)
This of course depends on your schema. You can index more than one column as well and can apply UNIQUE constraints to ensure that each value is used only once.
On large tables the CREATE INDEX operation will be brutally slow to create the first time, so schedule some downtime if necessary. Once created it will be kept up-to-date automatically.

Insert 1 Million Records in MySQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a simple table 'MyCombs' with 3 columns. ID, Start & End. ID is autoincrement so I have no problem with that. For Start & End points, I have 1million records. These records are different. I have created Insert queries for these 1 miilion records. Now i am facing a problem. When i try to simply run the queries by copying 50,000 records each time in phpMyAdmin, it does not insert these records in table. Loading, Loading. I saw some solution where we have to create a sql format file. I tried but was not able to create such file. Fairly saying, i am completely new to this. Is there anyway i can insert these records into table??
You can achieve it by using 'Bulk Insert' either in MySql or SqlServer !!!
For More Information...refer the following link..
https://dev.mysql.com/doc/refman/5.5/en/optimizing-innodb-bulk-data-loading.html

Search Most Word from a Column in MySQL Query [closed]

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 'tweet' and its column 'text'. The column contains a sentence (many words) in each record. Then I wanna search the most word from the column. Is that possible to do that in MySQL query? If so, then I want to know also to add exception words like: 'a', 'I', etc...
I thought it's similar with this post
But it's using PHP.
I very appreciate for any help!
SQL is not the obvious tool for something like this. But, if you are going to use SQL, I would suggest that you parse the text into a TweetWords table, with one row per "tweet" and word in the tweet (along with position information).
If you are inserting the data through PHP, you can do the parsing there and then insert each word independently.
Then the count is easy, using a basic aggregation query.

Can I replace this code to use IN operator as well? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Our code is using create/drop table, while generating VR4 queue orders in our database.
When number of websites is less than 250, code is using IN operator and generating reports. ce.website_id in (" . (join ",", #{$website_id}) . ")
When we have more than 250 websites, our code is creating tables (name like Temp_tablename) and using table joining instead of IN operator. Can I replace this code to use IN operator as well? Will there be any performance issue, if IN operator is used with more input values?
As mentioned by Stan, using a temporary table rather than a large IN is the preferred way to go.
When MySQL gets a large data block from the user it stores it in a temporary table and uses a JOIN to look through it. This is easier for MySQL to do than to actually look for each of your values in the IN SQL part.
You can skip this temporary table, by first storing in a table your web site list:
REPLACE INTO tblWebSitesToHandle
(Session_ID, WebSite)
VALUES
('**unique_number**', '**website_id**'),
('**unique_number**', '**website_id**'), ...
Where unique_number will be some number you chose, and then toss away once the query ends - but it will help you manage the list of websites to handle for your query
Then in your SQL that you are currently using instead of IN (...) you will do a JOIN to this table and select from it the relevant Session_ID record.
After that is done, just remove from tblWebSitesToHandle the Session_ID data, it is no longer needed (I believe).