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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:54:59+00:00 2026-06-10T05:54:59+00:00

I read a while back this excellent answer by @Bill Karwin: https://stackoverflow.com/a/1313293/317889 This pretty

  • 0

I read a while back this excellent answer by @Bill Karwin:

https://stackoverflow.com/a/1313293/317889

This pretty much answers the question however, I have recently had to update my query to filter on the joined tables status.

I have written two queries below, similar to the queries in the post above. The first query which is the slow one works with the joined tables status filtering:

SELECT m.*, t1.* FROM mood m 
LEFT JOIN temper t ON ( m._id = t.mood_id ) 
WHERE grantee_username = "username" 
AND m.status_id != 1 // NOT INTERESTED IN THIS FILTER
AND t.status_id != 1 // FILTERING 
GROUP BY m._id;

With the second query I have no idea how to add the filtering to get it to work as above:

SELECT m.*, t1.* FROM mood m 
LEFT JOIN temper t1 ON ( m._id = t1.mood_id ) 
LEFT JOIN temper t2 ON ( t1.mood_id = t2.mood_id AND t1._id < t2._id ) 
WHERE t2._id IS NULL 
AND m.grantee_username = "username" 
AND m.status_id != 1; // NOT INTERESTED IN THIS FILTER

The first query works perfectly but is deemed to be slower than the second query.

The second query works at brining back all mood records with their relating last temper record however that last temper record may have a status of 1 which I don’t want.

Any insight would be of interest. I could always just go with the first query but for the sake of performance I would like to figure out how to add the t.status_id filtering to the second query if possible.

  • 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-10T05:55:01+00:00Added an answer on June 10, 2026 at 5:55 am

    Ok, works out that it wasn’t too dificult after all:

    SELECT m.*, t1.* FROM mood m 
    LEFT JOIN temper t1 ON ( m._id = t1.mood_id AND t1.status_id !=1) 
    LEFT JOIN temper t2 ON ( t1.mood_id = t2.mood_id AND t1._id < t2._id AND t2.status_id !=1 ) 
    WHERE t2._id IS NULL 
    AND m.grantee_username = "username" 
    AND m.status_id != 1; // NOT INTERESTED IN THIS FILTER
    

    The filter (status_id) needs to be added to each JOIN.

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

Sidebar

Related Questions

(A while back I read this great post: http://aaronlongwell.com/2009/06/the-ruby-on-rails-cms-dilemma.html , discussing the Rails CMS
So, a while back I read a joke that went something like this: Never
according to some tutorials i read a while back, the const declaration makes a
A while back i read somewhere about how to improve upon the MVC pattern
I have part of my script that goes like this: while read line do
I've got a script like this: dyski=$(df -h) while read wiersz; do i=0; for
I read a while back that Quantum Computers can break most types of hashing
This is a classic c/p problem where some threads produce data while other read
A while back I read (before I lost it) a great book called GUI
I read ScottGu's blog entry ( http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx ) a while back, and it seems

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.