473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to import data into existing rows of a table?

I have moved 665 records off of Filemaker into mysql-4.0.18. I had a
great deal of trouble exporting a text field, possibly because it had
control characters that interferred with my field delimiter (also it
was from a Mac, and I'm new at this.)

So I have a table called invoices and another table called tasks, that
has only an invoice number and the work billed on that invoice number.
To see the work billed along with the other invoice data I have to do
a join, and this works but is clumsy for me. Since tasks.work is a
text field of 'infinite' variety I don't see the sense of keeping it
in a separate table like I would with clients' info; it belongs *in*
the invoice table, not just with it.

Is it possible to import this text data into a field in the invoice
table? I've messed around with this but it always appends the data as
new records. Perhaps I was doing an insert back then. Is the answer
something like 'load data infile 'workdone.csv' into invoices
(workdone);'

The invoices table was filled in a certain order (by invoice number)
and the workdone.csv was exported in the same order, so each invoice
row should get its correct text.

Is this a good thing, or am I thinking too 'flat-file-ish'?

Thanks,

r
Jul 20 '05 #1
3 2849
Reed Loefgren wrote:
Is it possible to import this text data into a field in the invoice
table?


What you want to do is add a field to the invoice table for the task
text, and UPDATE that field with the text value found in the
corresponding record that is currently in the tasks table. This is a
tricky thing to do in SQL, and in general cannot be done in one statement.

I can think of two different techniques to solve cases like this.

One method would be to generate a series of UPDATE statements, each of
which will update the value in one record of the invoice table. You can
even generate these statements as literal text from a select on the
legacy tasks table:
select concat('update invoices set task = \'', T.task_text,
'\' where invoice_number = ', T.invoice_number, ';')
from tasks T;

Capture the output of this query and then run it through mysql as a
script after you create the new column in the invoices table using ALTER
TABLE ADD COLUMN.

The other method would be to create a new table that has the same
structure as the old invoices table, plus an additional column for the
task text. Then fill that table using INSERT based on a join between
the old invoices table and the tasks table.
INSERT INTO invoices_new
SELECT I.*, T.task_text
FROM invoices I INNER JOIN tasks T using (invoice_number);

Then drop the old invoices table, and rename the new invoices table to
simply 'invoices'.

Regards,
Bill K.
Jul 20 '05 #2
....
The other method would be to create a new table that has the same
structure as the old invoices table, plus an additional column for the
task text. Then fill that table using INSERT based on a join between
the old invoices table and the tasks table.
INSERT INTO invoices_new
SELECT I.*, T.task_text
FROM invoices I INNER JOIN tasks T using (invoice_number);

Then drop the old invoices table, and rename the new invoices table to
simply 'invoices'.

Regards,
Bill K.


Bill,

This I'm pretty sure I can do, and it's better than both my scripting
abilities and my understanding right now of inner/outer/left/right
joins.

thanks,

r
Jul 20 '05 #3

"Reed Loefgren" <rl***@interfold.com> skrev i en meddelelse
news:d3*************************@posting.google.co m...
I have moved 665 records off of Filemaker into mysql-4.0.18. I had a
great deal of trouble exporting a text field, possibly because it had
control characters that interferred with my field delimiter (also it
was from a Mac, and I'm new at this.)

So I have a table called invoices and another table called tasks, that
has only an invoice number and the work billed on that invoice number.
To see the work billed along with the other invoice data I have to do
a join, and this works but is clumsy for me. Since tasks.work is a
text field of 'infinite' variety I don't see the sense of keeping it
in a separate table like I would with clients' info; it belongs *in*
the invoice table, not just with it.

Is this a good thing, or am I thinking too 'flat-file-ish'?

You are.

One invoice can have multiple tasks, right?

Better get the hang of joins, it is really not that difficult.

Leif
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Doug Baroter | last post by:
Hi, One of my clients has the following situation. They use Access DB for data update etc. some business functions while they also want to view the Access data quickly and more efficiently in...
3
by: grawsha2000 | last post by:
Greetings All, I have a excel file which is originally a sqlserver table that was exported as a excel file. I have added more data to this excel file and now want to import it again to its...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
3
by: wildbill | last post by:
I have an Excel spreadsheet with 1000+ rows that I need to import into an Access 2002 db once a month or so. I then need to use that information to update any existing records(multiple fields may...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
4
by: Gregor Kovač | last post by:
Hi! When I'm using IMPORT with INSERT_UPDATE I sometimes get SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. I'm not sure why this happens....
1
by: JC | last post by:
I have a table which is replicated for after images only. I tried to do an import using the replace option into the source table with data. For some of the rows, they were not in the import file,...
4
by: db2admin | last post by:
Hello, If i import data into tables, import will write all warnings in message file and will tell me why any exception row is rejected. I wanted to get exception rows in seperate table which i...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet ive developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.