Kyong Kim wrote:
I needed to give greater detail.
parent_id isn't unique. The table has a composite primary key (parent_id,
seq_id).
Here's a better schema def
CREATE TABLE sometable (
parent_id INT(10) NOT NULL,
seq_id INT(10) AUTO_INCREMENT,
child_id INT(10) NULL,
PRIMARY KEY(parent_id, seq_i
UPDATE, I think this will solve
> the problem with one statement.
>
> Rodrigo Ferreira
>
> --- On *Wed, 3/24/10, Johnny Withers * wrote:
>
>
> From: Johnny Withers
> Subject: Re: SELECT and INSERT if no row is returned
> To: "Kyong Kim"
> Cc: "my
First, if you want no duplicate parent_id, make it unique key (as JW saids).
Look at INSERT ... ON DUPLICATE KEY UPDATE, I think this will solve the problem
with one statement.
Rodrigo Ferreira
--- On Wed, 3/24/10, Johnny Withers wrote:
From: Johnny Withers
Subject: Re: SELECT and INSERT if
Make parent_id a unique key. Doing a select first and inserting if no
result will work 99.9% of the time; however, consider 2 rows being
inserted at the same time.
JW
On Tuesday, March 23, 2010, Kyong Kim wrote:
> I need to INSERT a row into a table only if it does not exist to
> insure that the
I need to INSERT a row into a table only if it does not exist to
insure that there won't be duplicate rows.
Due to the the usage case and the design of the primary key,
non-unique id + auto increment, I don't think insert ignore is an
option.
What would be simplest and cheapest way to make sure th