0

I'm having a blonde moment, I have a timestamp and value column that I want to query from a PHP MySQL table "mytable". However I would like only get one value and the corresponding timestamp for the one value. For example:

value,timestamp
23,2016-09-01 00:04:05 
23,2016-09-01 00:04:05 
23,2016-09-02 01:04:05 < --- extract this
24,2016-09-02 01:05:13
24,2016-09-03 01:04:24 
27,2016-09-03 03:24:34 
27,2016-09-04 04:24:42
27,2016-09-05 05:54:12 
27,2016-09-06 00:04:05
27,2016-09-07 00:04:05 < --- extract this
28,2016-09-08 00:04:05 < --- extract this

I want to be able to extract from the above table, onevalue and it's corresponding timestamp

value,timestamp
23,2016-09-02 01:04:05
27,2016-09-07 00:04:05
28,2016-09-08 00:04:05

Q: What would be the query look like?

3
  • 1
    How are those unique? I don't see any pattern in what you want to output. Commented Sep 15, 2016 at 5:12
  • I also don't see any pattern, but this looks like this might be a gaps and islands problem. Have you tried anything yet? Commented Sep 15, 2016 at 5:12
  • @SamiKuhmonen, my apologies, I fixed up my question, I just want the latest time stamp with a one-off value i.e no duplicate values... again my apologies Commented Sep 15, 2016 at 5:29

1 Answer 1

1

Try this

SELECT
    value,
    MAX(TIMESTAMP)
FROM
    yourTable
GROUP BY
    value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.