>
> Now I have one more problem. How do I insert only once if value does not
> exist? eg:
>
You should create a unique index on the appropriate fields. For example:
CREATE UNIQUE INDEX indexname ON table (field1, field2)
Then the insert will fail if this particular combination of the values of
(field1, field2) is already in the table.
Be careful if the insert is inside a transaction, tough. If it fails due to
non-uniqueness your transaction will be aborted (all further queries ignored
untill a COMMIT or ROLLBACK).