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 6365503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:18:06+00:00 2026-05-25T00:18:06+00:00

I want to generate a thread-like view In the table I have from,to,date and

  • 0

I want to generate a thread-like view

In the table I have from,to,date and some other columns

I want to output the rows grouped by from AND to

example data in DB

from,to,date
a,b,somedate
a,c,somedate
b,a,somedate

Query:

SELECT 
    from, to, date 
FROM 
    data 
GROUP BY 
    from, to 
ORDER BY 
    date DESC;

The output I expect is like this: (where from and to is grouped together)

a,b,somedate
a,c,somedate

(b,a,somedate not shows because its in the a,b group) 

but it doesn’t ..

The general idea is to have a Messaging View “by user” ..
where the list is sorted by recipients,date (not by message) …

  • 1 1 Answer
  • 1 View
  • 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-25T00:18:07+00:00Added an answer on May 25, 2026 at 12:18 am

    If you want one row returned for every (from, to) combination:

    SELECT one, two, MIN(somedate) 
    FROM
    ( SELECT `from` AS one, `to` AS two, somedate 
      FROM data 
      WHERE `from` <= `to`
    UNION ALL
      SELECT `to`, `from`, somedate 
      FROM data 
      WHERE `from` > `to`
    ) AS tmp
    GROUP BY one
           , two
    ORDER BY one
           , two
    

    or, if you want all records:

    SELECT one, two, somedate 
    FROM
    ( SELECT `from` AS one, `to` AS two, somedate 
      FROM data 
      WHERE `from` <= `to`
    UNION ALL
      SELECT `to`, `from`, somedate 
      FROM data 
      WHERE `from` > `to`
    ) AS tmp
    ORDER BY one
           , two
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate an HTML table from a couple specified parameters. Specifically, the
i want to generate a unique number from a table. It has to be
Let's say I have a class of 30 students and want generate every possible
I want to generate a list of files where the name consists of ${filename}.${date}
I want to generate a bar graph from from a csv file my data
I want to generate a LaTeX document from Objective-C and compile it with pdfLatex
I have a thread in java/Android like this: Handler handler = new Handler() {
I have an ASP.NET page that I want to be able to generate and
I have a ByteBuffer called buffer. I want to generate a new buffer that
I want to know what has been done when URL.openconnection(). i have done 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.