Update Syntax
am 26.07.2009 19:11:02 von Victor Subervi
--0016364ee8ac03fdca046f9eeca5
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi;
I would like to test the following:
update maps set map where site=mysite;
to see if there is such an entry in maps. If there is, then update. If there
is not, then I would like to execute an insert statement. How do I do that?
TIA,
Victor
--0016364ee8ac03fdca046f9eeca5--
Re: Update Syntax
am 26.07.2009 19:17:51 von Michael Dykman
from: http://dev.mysql.com/doc/refman/5.1/en/insert.html:
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name=3D{expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE
col_name=3Dexpr
[, col_name=3Dexpr] ... ]
The ON DUPLICATE KEY predicate tells you that if you create a unique
key for when ever your 'search' criteria is, you can get this
behaviour like so:
INSERT INTO mytable SET col1 =3D val1, ... ON DUPLIATE KEY UPDATE
- michael dykman
On Sun, Jul 26, 2009 at 1:11 PM, Victor Subervi wr=
ote:
> Hi;
> I would like to test the following:
>
> update maps set map where site=3Dmysite;
>
> to see if there is such an entry in maps. If there is, then update. If th=
ere
> is not, then I would like to execute an insert statement. How do I do tha=
t?
> TIA,
> Victor
>
--=20
- michael dykman
- mdykman@gmail.com
Don=92t worry about people stealing your ideas. If they=92re any good,
you=92ll have to ram them down their throats!
Howard Aiken
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: Update Syntax
am 26.07.2009 19:18:58 von Darryle steplight
Hi Vicor,
Look into INSERT ON DUPLICATE or REPLACE statements. You need to
have a primary key or unique key for these too work.
On Sun, Jul 26, 2009 at 1:11 PM, Victor Subervi wrote:
> Hi;
> I would like to test the following:
>
> update maps set map where site=mysite;
>
> to see if there is such an entry in maps. If there is, then update. If there
> is not, then I would like to execute an insert statement. How do I do that?
> TIA,
> Victor
>
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: Update Syntax
am 26.07.2009 19:47:22 von Victor Subervi
--0016364ef4d6f660ee046f9f6d33
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Perfect. Thank you.
Victor
On Sun, Jul 26, 2009 at 2:18 PM, Darryle Steplight wrote:
> Hi Vicor,
> Look into INSERT ON DUPLICATE or REPLACE statements. You need to
> have a primary key or unique key for these too work.
>
> On Sun, Jul 26, 2009 at 1:11 PM, Victor Subervi
> wrote:
> > Hi;
> > I would like to test the following:
> >
> > update maps set map where site=mysite;
> >
> > to see if there is such an entry in maps. If there is, then update. If
> there
> > is not, then I would like to execute an insert statement. How do I do
> that?
> > TIA,
> > Victor
> >
>
>
>
> --
> A: It reverses the normal flow of conversation.
> Q: What's wrong with top-posting?
> A: Top-posting.
> Q: What's the biggest scourge on plain text email discussions?
>
--0016364ef4d6f660ee046f9f6d33--