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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:08:15+00:00 2026-06-12T22:08:15+00:00

i would like to fetch data from table a,b,c but order by most recent

  • 0

i would like to fetch data from table a,b,c but order by most recent data of table response

table casework has this structure ( simplified):

casework_id | problem   | user_id          
------------+-----------+-------
1           | Problem1  | 1  
2           | Problem2  | 2
3           | Problem3  | 1
4           | Problem4  | 3

table user has this structure ( simplified):

user_id | name         
--------+-----------------
1       | peter  
2       | Sam  
3       | Tom  
4       | Steve

table response has this structure ( simplified):

response_id | response   | casework_id | created           
------------+-----------+--------------+-------
1           | responce1  |  1      | 2012-10-14 11:28:31
2           | responce2  |  1      | 2012-9-10 11:28:31 
3           | responce3  |  1      | 2012-9-2 11:28:31
4           | responce4  |  3      | 2012-8-3 11:28:31
4           | responce5  |  3      | 2012-8-2 11:28:31

I am looking the query to fetch data order by latest responce and group by casework_id

I. e. required out put is 

casework_id | problem   | name  | responce  | created        
------------+-----------+-------+-----------+---------
1           | Problem1  | peter | responce1 | 2012-10-14 11:28:31
2           | Problem2  | Sam   | Null      | Null
3           | Problem3  | peter | responce4 | 2012-8-3 11:28:31 
4           | Problem4  | Tom   | Null      | Null

I would be most grateful if one of you kind people could point me in the right direction.

  • 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-06-12T22:08:17+00:00Added an answer on June 12, 2026 at 10:08 pm

    You can use the following:

    select c.casework_id,
      c.problem,
      u.name,
      r2.response,
      r1.created
    from casework c
    left join user u
      on c.user_id = u.user_id
    left join
    (
      select max(created) created, casework_id
      from response r
      group by casework_id
    ) r1
      on c.casework_id = r1.casework_id
    left join response r2
      on r1.created = r2.created
      and r1.casework_id = r2.casework_id
    

    See SQL Fiddle with Demo

    If you want to include both the user that created the casework and then who responsed, then you will want to join on the user table twice:

    select c.casework_id,
      c.problem,
      u1.name CreatedByName,
      r2.response,
      r1.created,
      u2.name ReponseName
    from casework c
    left join user u1
      on c.user_id = u1.user_id
    left join
    (
      select max(created) created, casework_id
      from response r
      group by casework_id
    ) r1
      on c.casework_id = r1.casework_id
    left join response r2
      on r1.created = r2.created
      and r1.casework_id = r2.casework_id
    left join user u2
      on r2.user_id = u2.user_id
    

    See SQL Fiddle with demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to fetch data from a table ordered by priority column that is
I have a table with data from the database, I would like it to
I have managed to display data in one column table, but would like to
My Flash movie would like communicate with MySQL server to fetch and save data
I would like to fetch the result set from a function for each row
I have this table : I would like to delete same rows. For example
I'm trying to populate a table structure with around 5 fields of data from
As the title says, I would like to update this ajax fetch every x
I have a csv file with dump data of table and I would like
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode

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.