1

Im new at SQL and Im currently using it for one of my projects.

I want to delete the data in a field eg. if it was not changed for 30 days.

I thought of something like this - DELETE eventLog WHERE date < (lastChange - INTERVAL 30 DAY);

  1. eventLog is a varchar
  2. lastChange is a DATE

I tried it but I think it does not really worked.

Does somone has a better way to do that?

Thanks

jokey
  • 37
  • 2
  • 6

1 Answers1

1

DELETE does not remove values from a field. For varchar you want something like:

UPDATE tableName
SET eventLog = ''
WHERE ...

OR

UPDATE tableName
SET eventLog = NULL
WHERE ...

DELETE is used to remove entire rows from a table.

Also as for the last 30 days part see this:

MySQL Query - Records between Today and Last 30 Days

Community
  • 1
  • 1
duncan
  • 1,161
  • 8
  • 14
  • Thanks. Can I use this in the same script, in which my tabel is created, because it should update the tabel, everytime the eventLog was not changed for 30 Days? – jokey Nov 15 '16 at 15:00
  • @jokey I'm not sure what you mean. – duncan Nov 15 '16 at 15:02
  • So just put it in a script that runs twice a day... sorry still not sure what isn't clear. Maybe some more details on how you are running it would help. – duncan Nov 15 '16 at 15:12