Solved

insert else update

Posted on 2013-05-20
4
298 Views
Last Modified: 2013-05-22
CREATE TABLE `host_email` (
  `host_email_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `event_code_id` int(11) DEFAULT NULL,
  `event_code_admins_id` int(11) DEFAULT NULL,
  `host_email_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `host_email_email` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `host_email_sent` tinyint(4) DEFAULT NULL,
  `host_email_first_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  `host_email_last_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  `guest_user_id` int(11) DEFAULT NULL,
  `host_email_type` int(11) DEFAULT NULL,
  `course1` int(11) DEFAULT NULL,
  `course2` int(11) DEFAULT NULL,
  `course3` int(11) DEFAULT NULL,
  `course4` int(11) DEFAULT NULL,
  `nominate` int(11) DEFAULT NULL,
  `member` int(11) DEFAULT NULL,
  `host_email_member` int(11) DEFAULT NULL,
  `additional_notes` varchar(2000) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`host_email_id`)
) ENGINE=MyISAM AUTO_INCREMENT=19682 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci$$



insert into host_email (event_code_id,event_code_admins_id,user_id,host_email_name,host_email_first_name,host_email_last_name,host_email_email,host_email_type,host_email_member,nominate,course1,course2,course3,course4,additional_notes) select '87','72','11688','robert jones','robert','jones','email@email.com',4, '1', '', '1', '6', '3', '', 'almost vegitarian' from dual where not exists (select 1 from host_email where host_email_email = 'email@email.com' and event_code_id='87' and event_code_admins_id='72' and user_id='11688' and host_email_type=4);


but also want to update if
host_email_email,event_code_id,event_code_admins_id,user_id,host_email_type
is already there


I think it would be too difficult to have 6 keys in one table,
so I think command would be easier
0
Comment
Question by:rgb192
  • 2
  • 2
4 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39182754
You can use one key which references multiple columns.  You might consider REPLACE INTO (which is a unique-to-MySQL extension of the standard).  You might consider ON DUPLICATE KEY UPDATE.
0
 

Author Comment

by:rgb192
ID: 39182980
changed to replace into
'new value'

replace into host_email (event_code_id,event_code_admins_id,user_id,host_email_name,host_email_first_name,host_email_last_name,host_email_email,host_email_type,host_email_member,nominate,course1,course2,course3,course4,additional_notes) select '87','72','11688','new value','robert','jones','email@email.com',4, '1', '', '1', '6', '3', '', 'almost vegitarian' from dual where not exists (select 1 from host_email where host_email_email = 'email@email.com' and event_code_id='87' and event_code_admins_id='72' and user_id='11688' and host_email_type=4); 

Open in new window


no change in db
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39184774
I think we would need the SSCCE, including some data to test with.
http://dev.mysql.com/doc/refman/5.0/en/replace.html
0
 

Author Closing Comment

by:rgb192
ID: 39188927
replace link provides examples,
thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now