Answer the question
In order to leave comments, you need to log in
How to check if an existing row is identical before inserting a new one?
Good afternoon, please tell me if it is possible to put additional logic in INSERT, or do you need separately logic first, and then the action
There is a table
id ; login ; host ; event_id ; date
1; strelkov.av ; home_pc ; 1 ; 11:00:00
2; strelkov.av ; home_pc ; 2 ; 12:00:00
3; strelkov.av ; home_pc ; 3 ; 13:00:00
4; strelkov.av ; home_pc ; 1 ; 14:00:00
insert into table (login, host, event_id, date) values ('strelkov.av', 'home_pc', '1', now());
Answer the question
In order to leave comments, you need to log in
INSERT INTO my_table (login, host, event_id)
SELECT 'strelkov.av', 'home_pc', 1
FROM my_table
WHERE login='strelkov.av'
AND host='home_pc'
AND event_id=1
HAVING COUNT(*)=0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question