Hi. I have a table : code, name and date fields, sorted by date. 100 Luiz 2016-03-31 100 Luiz 2016-04-30 100 Luis 2016-05-31 100 Luis 2016-06-30 200 Juam 2016-04-30 200 Juan 2016-05-31 300 Rosa 2016-04-30 300 Rosa 2016-05-31 300 Rossana 2016-06-30 HTML: Some records of some codes was changed. I need to filter and show that records changed. Like this: 100 Luis 2016-05-31 200 Juan 2016-05-31 300 Rossana 2016-06-30 HTML: I tried to use this: select code, distinct name, date from table group by code PHP: But does not work. I accept suggestions.
Like PoPSiCLe said, from the information you have provided, you are unable to tell if a field has changed or not. The method I would use is something like: id | code | name | created_at | updated_at When you create each individual entry, update the created_at to NOW(). Each time you update a record, updated the created_at with NOW(). This way you will know when each record was last updated, and are able to query the results to show the last modified entries, or give it a range, eg updated between X and Y dates.
But that will still not tell if something has been updated more than once. A better approach would be creating a separate table with the id for the data, and an update-date. Of course you could do a check for this based on current date, and query for updates happening the last 5 days or so, but the whole construction is a bit silly.
This table contains monthly movements. It is in chronological order. And the only way to know whether or not renamed is compared with the previous name. You can see that in the example I gave.
Can't you just fetch the latest entry per ID? That won't tell you about changes, but it will list the current/updated content?
Use something like that: SELECT code, name, max(date) FROM tabla group by code PHP: ?? This show the last name in the last date. Dont you? I need the date when the name was change. 100 PAUL 2016-03-31 100 PAUL 2016-04-30 100 ROBERT 2016-05-31 <-- Here the name was change, so this date is what I need. 100 ROBERT 2016-07-31 HTML:
Then you will have to do something else, because that table-construct is not working for your needs. You should really have a check for changes, and mark the changed ones. Something like (when it's being updated), *if name != $SQL-name // set updated = 1* (pseudo-code). If you don't have that, you will have to pull the data, and parse it, most likely.
Like this? UPDATE table SET flag = 'X' where name<> (SELECT name FROM table table GROUP BY code ORDER BY date) PHP: or something that?
Yes, something like that, yes - That way you can pinpoint the latest changes, or if there has been a change.