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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:58:44+00:00 2026-05-26T04:58:44+00:00

Trying to join a table fab_qouta.qoutatype to at value inside a sub query fab_status_members.statustype

  • 0

Trying to join a table “fab_qouta.qoutatype” to at value inside a sub query “fab_status_members.statustype” but it returns nothing.

If I join the 2 tables directly in a query the result is correct.

Like this:

select statustype, takst 
from   
  fab_status_members AS sm
    join fab_quota as fq
      ON fq.quotatype = sm.statustype

So I must be doing something wrong, here the sub query code, any help appreciated

select
  ju.id,
  name,
  statustype,
  takst

from jos_users AS ju 
  join 
    ( SELECT sm.Members AS MemberId, MaxDate , st.statustype 
      FROM fab_status_type AS st
        JOIN fab_status_members AS sm 
          ON (st.id = sm.statustype) -- tabels are joined 
        JOIN 
          ( SELECT members, MAX(pr_dato) AS MaxDate -- choose members and Maxdate from
            FROM fab_status_members 
            WHERE pr_dato <= '2011-07-01' 
            GROUP BY members
          )
          AS sq
          ON (sm.members = sq.members AND sm.pr_dato = sq.MaxDate)
     ) as TT
     ON ju.id = TT.Memberid
  join fab_quota as fq 
    ON fq.quotatype = TT.statustype 
GROUP BY id

Guess the problem is in the line: join fab_quota as fq ON fq.quotatype = TT.statustype

But I can’t seem to look through it 🙁

Best regards

Thomas

  • 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-26T04:58:45+00:00Added an answer on May 26, 2026 at 4:58 am

    It looks like you are joining down to the lowest combination of per member with their respective maximum pr_dato value for given date. I would pull THIS to the FIRST query position instead of being buried, then re-join it to the rest…

    select STRAIGHT_JOIN
          ju.id,
          ju.name,
          fst.statustype,
          takst
       from 
          ( SELECT 
                  members, 
                  MAX(pr_dato) AS MaxDate
               FROM 
                  fab_status_members 
               WHERE 
                  pr_dato <= '2011-07-01' 
               GROUP BY 
                  members ) MaxDatePerMember
    
          JOIN jos_users ju
             on MaxDatePerMember.members = ju.ID
    
          JOIN fab_status_members fsm
             on MaxDatePerMember.members = fsm.members
            AND MaxDatePerMember.MaxDate = fsm.pr_dato
    
             JOIN fab_status_type fst
                on fsm.statustype = fst.id
    
                JOIN fab_quota as fq
                   on fst.statusType = fq.quotaType
    

    I THINK I have all of what you want, and let me reiterate in simple words what I think you want. Each member can have multiple status entries (via Fab_Status_Members). You are looking for all members and what their MOST RECENT Status is as of a particular date. This is the first query.

    From that, whatever users qualify, I’m joining to the user table to get their name info (first join).

    Now, back to the complex part. From the first query that determined the most recent date status activity, re-join back to that same table (fab_status_members) and get the actual status code SPECIFIC to the last status date for that member (second join).

    From the result of getting the correct STATUS per Member on the max date, you need to get the TYPE of status that code represented (third join to fab_status_type).

    And finally, from knowing the fab_status_type, what is its quota type.

    You shouldn’t need the group by since the first query is grouped by the members ID and will return a single entry per person (UNLESS… its possible to have multiple status types in the same day in the fab_status_members table… unless that is a full date/time field, then you are ok)

    Not sure of the “takst” column which table that comes from, but I try to completely qualify the table names (or aliases) they are coming from, buy my guess is its coming from the QuotaType table.

    … EDIT from comment…

    Sorry, yeah, FQ for the last join. As for it not returning any rows, I would try them one at a time and see where the break is… I would start one at a time… how many from the maxdate query, then add the join to users to make sure same record count returned. Then add the FSM (re-join) for specific member / date activity, THEN into the status type… somewhere along the chain its missing, and the only thing I can think of is a miss on the status type as any member status would have to be associated with one of the users, and it should find back to itself as that’s where the max date originated from. I’m GUESSING its somewhere on the join to the status type or the quota.

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

Sidebar

Related Questions

I'm trying to join two relatively simple tables together, but my query is experiencing
I'm trying to write a query to join a user table to an activity
I'm trying to work out a query that self join itself on a table
This is my query using entity manager. Trying to join 2 table with play
I'm trying to join two table (call them table1 and table2) but only return
I'm trying to join an additional table to my query and I ran into
I am trying to join three tables within an update statement, but I have
Im having issues trying to join a table twice. I have 3 tables: Users,
I am trying to join 3 table in LINQ. var fromCities = from c
I am trying to join my users table with another table using the following

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.