473,668 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

INSERT ... SELECT ... ON DUPLICATE KEY UPDATE not working for me.

Hello team. I'm running mysql 4.0.20-standard and i'm trying to do a
query like this:

INSERT IGNORE
INTO `DonorPledges` (
nDonor_id,
nPledgeYear,
nTotalPaid,
nTotalPledge )
SELECT
DonorInfo.nDono r_id,
'2006',
DonorHolding.nS ysYrPaid,
(
DonorHolding.nJ an+DonorHolding .nFeb+DonorHold ing.nMar+

DonorHolding.nA pr+DonorHolding .nMay+DonorHold ing.nJun+

DonorHolding.nJ ul+DonorHolding .nAug+DonorHold ing.nSep+

DonorHolding.nO ct+DonorHolding .nNov+DonorHold ing.nDec )
FROM `DonorHolding`
LEFT JOIN `DonorInfo` ON

`DonorHolding`. `nMemberID`=`Do norInfo`.`nMemb erID`
ON DUPLICATE KEY UPDATE
nTotalPaid = DonorHolding.nS ysYrPaid,
nTotalPledge =
(
DonorHolding.nJ an+DonorHolding .nFeb+DonorHold ing.nMar+

DonorHolding.nA pr+DonorHolding .nMay+DonorHold ing.nJun+

DonorHolding.nJ ul+DonorHolding .nAug+DonorHold ing.nSep+

DonorHolding.nO ct+DonorHolding .nNov+DonorHold ing.nDec )

I've stripped it down a bit, because it's an extremely verbose query,
but that is all of the main elements of it. The schema is exported
below (also stripped down a bit). Is it my syntax? Can i not do left
joins when doing an insert...select ...on dup key upd? Is it my mysql
version? Anyone who could point me at any useful info would be my
hero. The mysql docs on the subject are not as clear as they could be,
and i'm unsure as to whether or not i'm following them to spec. Thank
you very much!

-Brendan

Schema:

CREATE TABLE DonorHolding (
nMemberID int(20) unsigned NOT NULL default '0',
nJan int(10) unsigned NOT NULL default '0',
nFeb int(10) unsigned NOT NULL default '0',
nMar int(10) unsigned NOT NULL default '0',
nApr int(10) unsigned NOT NULL default '0',
nMay int(10) unsigned NOT NULL default '0',
nJun int(10) unsigned NOT NULL default '0',
nJul int(10) unsigned NOT NULL default '0',
nAug int(10) unsigned NOT NULL default '0',
nSep int(10) unsigned NOT NULL default '0',
nOct int(10) unsigned NOT NULL default '0',
nNov int(10) unsigned NOT NULL default '0',
nDec int(10) unsigned NOT NULL default '0',
nSysYrPaid float NOT NULL default '0',
nSysYrPRDedPled ge int(11) NOT NULL default '0',
UNIQUE KEY iMemberID (nMemberID)
) TYPE=MyISAM COMMENT='The holding information for data import';

CREATE TABLE DonorInfo (
nDonor_id int(11) unsigned NOT NULL auto_increment,
nLogin_id int(11) NOT NULL default '0',
nMemberID varchar(64) NOT NULL default '',
nSysYrPaid float NOT NULL default '0',
nSysYrPRDedPled ge int(11) NOT NULL default '0',
PRIMARY KEY (nDonor_id),
UNIQUE KEY iMemberID (cEnvisageMembe rID)
) TYPE=MyISAM COMMENT='The basic information for a Donor';

CREATE TABLE DonorPledges (
nDonor_id int(11) unsigned NOT NULL default '0',
nPledgeYear int(4) NOT NULL default '0',
nTotalPledge float NOT NULL default '0',
nTotalPaid float NOT NULL default '0',
PRIMARY KEY (nDonor_id,nPle dgeYear)
) TYPE=MyISAM COMMENT='Donor Pledge info, 1:1 with DonorInfo';

Feb 8 '06 #1
0 2081

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

Similar topics

2
16415
by: jtw | last post by:
I need to update a statistics table through out the day. I would like to insert the first data sampling of the data, then update the existing record for the rest of the day. The problem is that I do not alway know when the first sampling will start. Keys for the table are username and date. So each user will have only one entry per day. I have been checking to see if the record exists - select .. where username=... AND date =.... ...
6
2234
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a product in the database with that ID (primary key), just UPDATE the price, and if there is no product with that ID it should do an INSERT for that item. Now I've tried it in several ways and I can't seem to get it to execute
2
573
by: Nick | last post by:
Im trying to insert a bunch of rows into a table. If the row already exists id like to update the row 'counter'. For example... INSERT INTO table1 SELECT field1, field2 FROM table2 ON DUPLICATE KEY UPDATE field2 = 1 Is it possible to use both INSERT... SELECT... with ON DUPLICATE KEY? I cant get it to work.
0
2881
by: Suler Abou | last post by:
Hi, I'm having a problem with an SQL statement, I have a statement that goes like this: "INSERT INTO table VALUES('TransID','CID',etc...);" it basically adds new data to a table. When the form is posted it adds the data just fine. However, when you try to add more new data it adds the data and it duplicates it again with different transaction ID.
2
6545
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the assignment of version numbers: CREATE TRIGGER "trg_audio_file_insert" BEFORE INSERT ON "public"."audio_file" FOR EACH ROW EXECUTE PROCEDURE "public"."trg_audio_file_insert"(); My trigger function looks like this...
20
18344
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've been doing something like delete from foo where name = 'xx'; insert into foo values('xx',1,2,...);
8
3509
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a date that is supplied to the SP as a parameter. The SP is usually a lengthy process (it takes at least 30 mins). The problem is that SQL server 2000 Dev Edition doesn't allow me to insert new invoices that are "younger", while the SP is executing....
0
3969
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db.Name) conn.Open() Dim oda As New OleDb.OleDbDataAdapter("select " & sqlCols & " from ;", conn) Dim cb As New OleDb.OleDbCommandBuilder(oda) cb.QuotePrefix = "" oda.UpdateCommand =...
1
6342
by: nadavgg | last post by:
Hi, I have recently developed a C# application using Linq. I am getting from an external database a list of profiles I need to process, some are new and some are already in the database, and need to be updated. What I do today is go over the profile list and check each profile if such exists I update otherwise I insert - this solution is working fine. I am sure there is a way to use bulk insert/update something like UPDATE ON DUPLICATE, this...
0
8382
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7405
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.