Author |
Topic |
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 11:47:18
|
Two columns, 1000 rows, Column 1 - UsernameColumn 2 - Title1000 Rows with data in the Username column, but empty 1000 rows for title.I want to import into the existing empty rows for 1-1000 in the Title column without starting the data at row 1001 and so on.Can this be done?I have tried a couple of utilities but it only adds new rows, not update. (SQLyog) |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-01 : 12:43:51
|
You can't import into the existing rows, but you can import the titles into a table and use that to update the existing empty rows, if you can link them uniquely to your table. Something likeUPDATE tgtSET Title = srcTitleFROM myTable tgtINNER JOINsourceTable srcON tgt.? = src.?It sounds like your table has an identity column, and that may be usefulJimEveryday I learn something that somebody else already knew |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-07-01 : 12:48:38
|
Most of us use staging tables anyway (unless it's a full file replacement) to load data.This gives us the ability the audit the data as well a build processes to, nomalize, distribute modify, etc with T-SQL...WAIT THEY CALL THAT ETL now!!!! I am Soooo behind the times....I just don't have the ABILITY to make up new buzzwrods for things we have been doing...for...for...EONS...but I digressBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 13:25:12
|
Can someone give me an example of that INNER JOIN?Here is my tables:Source table name - threadsSource column - usernameDestination table name - csvimporttestDestination column - namez |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-01 : 13:55:36
|
I thought I did. Does username link to namez and does threads have the title info in it? If there's no link,then it'd be faster for you to update the 1000 rows manually.JimEveryday I learn something that somebody else already knew |
|
|
X002548
Not Just a Number
15586 Posts |
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 13:58:13
|
There are no keys for these columns, should I create a foreign key that links the two?Right now they have no link at all, just two columns in two tables..I apologize for the inexperienced questions, I am a junior DBA in training =) |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 14:49:08
|
threads.username has valuescsvimporttest.namez does noti want to move the values in threads.username into csvimporttest.namez and update the rows that are there, not add on rowsi dont think there can be keys set up since the values dont match? |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-01 : 15:22:20
|
This would be a lot simpler if you gave us the complete data structure for each table, sample data for each table, and your desired end result for your query. ( I wasn't kidding when I said it migtht just be faster to do it manually!)JimEveryday I learn something that somebody else already knew |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 15:24:14
|
Well, its over a million rows, lol. Manual is no option.Ok, both tables are varchar(250), not nullThey are forum titles, actually, such as the title of this forum, "How do you update existing rows with an import?"I am moving a forum from mssql to mysql, I exported all the rows from mssql into a txt file, and I also have them imported into a test column on a test table.What else would you like me to provide? Thanks for replying |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-01 : 15:56:47
|
Please give us the complete data structure for each table, sample data for each table, and your desired end result for your query.JimHint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxEveryday I learn something that somebody else already knew |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 16:22:40
|
SOURCE TABLE:table name - datafromfieldname | datatype | len | default | not null?titles | varchar | 250 | '' | Ysourcenames | varchar | 250 | '' | YDESTINATION TABLE:table name - datatofieldname | datatype | len | default | not null?titles | varchar | 250 | '' | Ynames | varchar | 250 | '' | YVALUES in datafromtitles | sourcenamesAdmin | MikeSupervisor | CoryUser | DannyVALUES in datatotitles | sourcenames | Mike | Cory | DannyI want to move "titles" data from "datafrom" into "titles" in "datato", starting with the same row the user "Mike" is on and so on. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-07-01 : 16:54:51
|
[code]UPDATE aSET a.titles = b.titles FROM datato a INNER JOIN datafrom b on a.sourcenames = b.sourcenames[/code]NOTE: Run it in some test environment and check if it produces your expected results. |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 16:57:57
|
quote: Originally posted by vijayisonly
UPDATE aSET a.titles = b.titles FROM datato a INNER JOIN datafrom b on a.sourcenames = b.sourcenames NOTE: Run it in some test environment and check if it produces your expected results.
Query : UPDATE a SET a.titles = b.titles FROM datato a INNER JOIN datafrom b ON a.sourcenames = b.sourcenames Error Code : 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM datato a INNER JOIN datafrom b ON a.sourcenames = b.sourcenames' at line 3Execution Time : 00:00:00:000Transfer Time : 00:00:00:000Total Time : 00:00:00:000 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-07-01 : 17:04:07
|
Oops..Sorry...I do not know the syntax for MySQL. This is a dedicated MS SQL Server Forum. You can get better help in a MySQL forum. |
|
|
noonz
Starting Member
33 Posts |
Posted - 2010-07-01 : 17:13:22
|
Yeah, but I am moving this from MSSQLThis data was exported from MSSQL |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-07-01 : 18:06:09
|
Move all your data, as is, from mysql database into sql server database and then try the query. JimEveryday I learn something that somebody else already knew |
|
|
|