Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:56:40+00:00 2026-05-25T18:56:40+00:00

Here is the example data set i have : id | messageread | timestamp

  • 0

Here is the example data set i have :

id | messageread | timestamp
 1 |       'yes' |       999
 1 |       'yes' |         0
 1 |        'no' |         0

I’m doing so :

SELECT *
FROM nvm
GROUP BY id

You will note that the data set is already ORDER BY timestamp DESC

As it should, MySQL is returning the first row.

What i’d want is MySQL to return the first row, but with messageread='no' IF messageread='no' in one of the grouped rows, no matter if the normally returned row is 'yes' or 'no'

Is that possible with MySQL? I promised myself to do as much as possible with MySQL and not PHP 🙂 Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:56:41+00:00Added an answer on May 25, 2026 at 6:56 pm

    In order to make sure all rows are from the same column do:

    SELECT * FROM table1 t1 
    LEFT JOIN table1 t2 ON ((t1.messageread, t1.id) < (t2.messageread, t2.id))
    WHERE T2.ID IS NULL
    

    This will select the minimum or maximum row from table1. And all columns will be from the same row.
    If it doesn’t work you need to change the < to a > it’s late here and I cannot test the query, but it should do the job.

    Warning, antipattern ahead
    This has the smell of rotten eggs all over it, but if you want to mix and match fast do:

    SELECT id, min(messageread), timestamp as random_timestamp
    FROM table1
    GROUP BY id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is often situation, but here is latest example: Companies have various contact data
I have used KD-tree(libkdtree++) to store a multi-dimensional data set, and the requirements here
Here is an example of the data set I am working with. I am
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
ex: <a><strike>example data in here</strike></a> I want everything inside the a tag, to the
I have a set a data that I need to calculate their consecutive mean
So I have a set of data that includes a column of dates and
I have a query that strips data from a XML string, inserts it into
I have a thread reading data from a bluetooth stream that sends the data
I have a longitudinal data set for a month in which there is some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.