0

I have a SQL query that creates an ID:

insert into category(related,text) values(?,?) 
on duplicate key update id=last_insert_id(id)

I then get my ID:

$id=$connect->lastinsertid()

Is there a way to distinguish between an ID that was found as a duplicate and one that is brand new using the query?

Maciek Semik
  • 1,872
  • 23
  • 43

1 Answers1

1

I think not directly. If you add created and updated date columns to your table, you can retrieve them and compare the values; if the record was newly inserted the dates shall be the same, if the record was updated, the dates shall differ. Insert should assign current date as a default value. Update events could fire a trigger to amend the date in the updatedate column

Caius Jard
  • 72,509
  • 5
  • 49
  • 80