1

I have a variable $Title and contains the following:

$Title = aa, bb, cc, dd, ee, ff
$Pubdate = aa, bb, cc, dd, ee, ff
$Link = aa, bb, cc, dd, ee, ff

and I insert it into the table with the column name Title. (Nice simple so far)

However, the variable updates every 1 hour and for example may turn into this.

$Title = cc, dd, ee, ff, gg, hh
$Pubdate = cc, dd, ee, ff, gg, hh
$Link = cc, dd, ee, ff, gg, hh


FYI: the values like "aa" of $Title are not the same value with "aa" of $Pubdate or of $Link, but are linked to each other
I was wondering if there is a way to avoid duplicate values going into the table again, so that only 'gg' and 'hh' goes in.
I know you can do it easily if you specify one value, like this

INSERT IGNORE INTO ytable (Title, Pubdate, Link) VALUES ('aa','aa');

but when it updates, I'm not sure what the next value will be so I need your help.

1
  • you can set title column as your primary key which wont allow to repeat the values present already. Commented Aug 18, 2015 at 5:37

1 Answer 1

2

You need to set a UNIQUE constraint on your database. That way, whenever you try to insert a row with the same value, it will be rejected by the database.

Here is a sample query, which you may have to adapt:

ALTER TABLE foo MODIFY Title VARCHAR(255) NOT NULL UNIQUE;

This ensures that the database will protest when you attempt to insert a row without a unique Title value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.