0

I have a table:

TableA
-----------
id | propertyA | propertyB

How can insert new row into table if row with propertyA and propertyB don't exist yet? PropertyA and propertyB are not unique so I can't use replace.

Ales
  • 515
  • 2
  • 7
  • 24
  • possible duplicate of [How to 'insert if not exists' in MySQL?](http://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql) – xdazz Jun 30 '12 at 10:29
  • "PropertyA and propertyB are not unique", did you mean the combinatioin of A and B is not unique? or seperatly? – Puggan Se Jun 30 '12 at 10:46
  • both. they are not defined as unique in any case – Ales Jun 30 '12 at 10:48

1 Answers1

0

You proberly can use somthing like:

INSERT INTO TableA(propertyA, propertyB)
SELECT :a, :b
FROM DUAL
LEFT JOIN TableA ON (propertyA = :a AND propertyB = :b)
WHERE TableA.id IS NULL;
Puggan Se
  • 5,431
  • 2
  • 19
  • 45