Hi, all.
Here is my problem:
Let's say i have table1 with columns a,b,c and table2 with cols x,y,z. Some of columns contain the same type of data from one table to the other, but others are totally different. Both tables have a very large number of rows (~70k).
Now, i need to replicate in table1 a column that exists only in table2, so i create a new column in table1, let's name it d, and i want to conditionally import column z from table2 in column d from table1. Conditionally means where a = x and b=y, for example.
i created this query: - UPDATE table1
-
SET d = (SELECT z FROM table2 WHERE table1.a=table2.x AND table1.b=table2.y)
i tested this query on a similar set of tables with a few rows and it does the job, but really slow (took ~1 minute to process 300 rows). I'm sure that if i run it on the 2 big tables it will take forever to complete or may not even finish at all.
any better ideas, faster alternatives ? (deleting and re-creating tables in not an option)
thanks
PS: i use mysql 5.0.26 on Win XP SP2 and MySQL Query Browser. I also tried to query from a PHP script, takes just as much.
4 2838
Hi, all.
Here is my problem:
Let's say i have table1 with columns a,b,c and table2 with cols x,y,z. Some of columns contain the same type of data from one table to the other, but others are totally different. Both tables have a very large number of rows (~70k).
Now, i need to replicate in table1 a column that exists only in table2, so i create a new column in table1, let's name it d, and i want to conditionally import column z from table2 in column d from table1. Conditionally means where a = x and b=y, for example.
i created this query: - UPDATE table1
-
SET d = (SELECT z FROM table2 WHERE table1.a=table2.x AND table1.b=table2.y)
i tested this query on a similar set of tables with a few rows and it does the job, but really slow (took ~1 minute to process 300 rows). I'm sure that if i run it on the 2 big tables it will take forever to complete or may not even finish at all.
any better ideas, faster alternatives ? (deleting and re-creating tables in not an option)
thanks
PS: i use mysql 5.0.26 on Win XP SP2 and MySQL Query Browser. I also tried to query from a PHP script, takes just as much.
Hi bubulle,
Welcome to TSDN.
I can suggest an alternative. -
UPDATE table1 LEFT OUTER JOIN table2 ON table1.a=table2.x AND table1.b=table2.y
-
SET table1.d=table2.z
-
You can also add WHERE table2.z IS NOT NULL. Please get back with performance details. I hope this helps.
Regards,
Pradeep
Hi bubulle,
Welcome to TSDN.
I can suggest an alternative. -
UPDATE table1 LEFT OUTER JOIN table2 ON table1.a=table2.x AND table1.b=table2.y
-
SET table1.d=table2.z
-
You can also add WHERE table2.z IS NOT NULL. Please get back with performance details. I hope this helps.
Regards,
Pradeep
Hi, Pradeep.
Thanks for the welcoming and for the suggestion. I tested it on the 300 rows tables and it took 55 seconds, compared to the ~63 needed to run it my way. So i worked up the courage and ran it on the big tables. Now, after all these hours, it finished processing the 73k rows.
thanks again for the tip :)
Bob.
Hi, Pradeep.
Thanks for the welcoming and for the suggestion. I tested it on the 300 rows tables and it took 55 seconds, compared to the ~63 needed to run it my way. So i worked up the courage and ran it on the big tables. Now, after all these hours, it finished processing the 73k rows.
thanks again for the tip :)
Bob.
Setting up Indexes should speed this up dramatically.
Hi, Pradeep.
Thanks for the welcoming and for the suggestion. I tested it on the 300 rows tables and it took 55 seconds, compared to the ~63 needed to run it my way. So i worked up the courage and ran it on the big tables. Now, after all these hours, it finished processing the 73k rows.
thanks again for the tip :)
Bob.
Hi Bob,
Sorry I missed out: adding Indexes to the searchable columns will definately speed up the process.
Regards,
Pradeep
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Caroline |
last post by:
I need to update a table by copying a column from another table
(having the same
structure, but on another database), from the record having the same
primary key.
1 - What is the correct...
|
by: Jan van Veldhuizen |
last post by:
The UPDATE table FROM syntax is not supported by Oracle.
I am looking for a syntax that is understood by both Oracle and SqlServer.
Example:
Table1:
id name city ...
|
by: shottarum |
last post by:
I currently have 2 tables as follows:
CREATE TABLE .
(
mhan8 int,
mhac02 varchar(5),
mhmot varchar(5),
mhupmj int
)
|
by: Mike Leahy |
last post by:
Hello all,
This question is related to updating tables - is there any way to calculate or
update the values in a column in a table to the values in a field produced by
a query result? An...
|
by: robert |
last post by:
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.
i assume that there is a threshold on the number of columns of
the...
|
by: Yaro |
last post by:
Hello
Could anyone tell how can I drop table conditionally (UDB 8.2 Win) ?
I have a script file
create table_1@
create table_2@
etc....
I need add to this script statement like that
|
by: Miro |
last post by:
I will ask the question first then fumble thru trying to explain myself so i
dont waste too much of your time.
Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an
index - i...
|
by: Michel Esber |
last post by:
Hi all,
DB2 V8 LUW FP 15
There is a table T (ID varchar (24), ABC timestamp). ID is PK.
Our application needs to frequently update T with a new value for ABC.
update T set ABC=? where ID...
|
by: BobLewiston |
last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |