android - MySQL TIMESTAMP behaving weirdly -
in chat application, use system.currenttimemillis()/1000
on android app send time message created @ mysql server, without milliseconds part. strange part is, table has 2 records same value of milliseconds. stranger when convert milliseconds readable time, values totally different!
here output of 2 different queries:
select max(unix_timestamp(created_at)), created_at, message messages mtype = 0 , groups_id = 1; max(unix_timestamp(created_at)) | created_at | message | +--------------------------------+---------------------+---------+ | 1464096148 | 2016-04-25 13:57:18 | select unix_timestamp(created_at), created_at, message messages mtype = 0 , groups_id = 1 order created_at desc limit 1; max(unix_timestamp(created_at)) | created_at | message | +--------------------------------+---------------------+---------+ | 1464096148 | 2016-05-24 18:52:28 | test
the output of last query remember sending client app.
nothing acting weird, acting should be.
when have more 1 record, , using aggregation function max()/min()/count()...
, if other columns without aggregation function has different values, 1 of them picked(not sure order, think randomly) .
so if them return same thing, query should use:
select unix_timestamp(created_at), created_at, message messages unix_timestamp(created_at) =(select max(unix_timestamp(created_at)) messages mtype = 0 , groups_id = 1) , mtype = 0 , groups_id = 1;
this make sure pick record, timestamp equals maximum timestamp, make sure pick correct record. when dealing aggregation functions, have specify each column 1 of values want.
Comments
Post a Comment