I need to include a record in a table, however before inclusion to avoid duplication it is necessary to do a check.
As I have a ID
column with property AUTO INCREMENT
, I can not use INSERT IGNORE INTO
.
Table
CREATE TABLE relacao (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_1 varchar(24) NOT NULL,
user_2 varchar(24) NOT NULL
)
Example
INSERT INTO relacao(user_1, user_2) values("Pedro", "Laura")
INSERT INTO relacao(user_1, user_2) values("Pedro", "Laura") /* não deixar inserir*/
How would query
be to check whether or not the record exists before insertion?