You probably want a unique index for those cols. Check out: http://www.mysql.com/doc/C/R/CREATE_TABLE.html (search for unique in page)
and http://www.mysql.com/doc/C/R/CREATE_INDEX.html -Joe > -----Original Message----- > From: Robert Martin [mailto:[EMAIL PROTECTED]] > Sent: Monday, October 01, 2001 12:50 PM > To: [EMAIL PROTECTED] > Subject: sql syntax INSERT > > > > Hi, > > I’m still learning sql so I hope this doesn’t sound to basic. > > I would like to find out if there is a way to insert a record > only when (X and Y) do not exist. > I have the value to check against stored in a variable. > > My table looks like the following: > > ID | X | Y > ----------------- > 1 | 10 | 20 > 2 | 11 | 21 > > ID is an auto-increment field, X and Y are INT(4). > > The syntax I’m looking for is sort of like this: > > Success: > INSERT INTO table_name (X, Y) > VALUES (10,23) WHERE (X <> myX) AND (Y <> myY) > > Fail: > INSERT INTO table_name (X, Y) > VALUES (10,20) WHERE (X <> myX) AND (Y <> myY) > > I know this won’t work, but I’m trying to avoid the overhead > of running a query and checking the result before each INSERT. > Would a “compound primary key” help? (To be honest I only > have a slight idea of what one is.) > Can one be created in MySQL? > > Thanks in advance, > Robert Martin > > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail > <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php