I have a table name Data with fields
Surmane, Name, Timestamp, PaidMoney, ChangAmmount, Address, Store
I want to have as result of a query the last record (DESC Timestamp Limit 1) of each person (group by Surname, Name) with the PaidMoney,ChangeAmmount, Address, Store
For example the result must be
Jones, Jim, 1290596796, 220.00, 0.25, 5th Avenue 120, Some Store1
Kojak, Ian, 1290596890, 1000.00, 50.25, Derek Avenue 1020, Some Store2
For each combination of Surname, Name must present the last record.
I try to do this with:
select `Surname`,
`Name`,
max(date_format(from_unixtime(`Timestamp`),'%Y/%m/%d - %T')) AS `dateTime`,
`PaidMoney`,
`ChangAmmount`,
`Address`,
`Store`
from `Data`
group by `Surname`, `Name`;
No good cause this doesn’t show correct data…..
Please Help…
Thank you…
Your table contains redundant datas of names and surnames.
It would be better if you put these datas in another table and refer to them using people id.
Moreover without an id, the use of concat will slow down the join performance, even if you would have an index.
edit.