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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:14:24+00:00 2026-05-31T17:14:24+00:00

We have a mechanism that lets a user view available Accelerators (attachments) for a

  • 0

We have a mechanism that lets a user view available Accelerators (attachments) for a given AsapStructure row (Node). They can bind multiple Accelerators to that individual Node.

I have two tables that are a many to many relationship (Has and belongs to Many)

AsapStructure hasAndBelongsToMany Accelerators

These two tables are joined via accelerators_nodes.

The scaled down schema is as follows:

AsapStructure:

  • id
  • title
  • progress_status
  • created
  • modified

Accelerators:

  • id
  • title
  • progress_status
  • created
  • modified

accelerators_nodes (Join Table)

  • id
  • node_id
  • accelerator_id
  • progress_status
  • created
  • modified

What I am trying to do, is select all ‘Accelerators’ that have a progress_status of 5, and the associated Node (AsapStructure – IF it exists. If it is NULL, i want to return the accelerator anyways, it just means that there is no relationship YET)

Each table has a progress_status field, this is just information about that particular row. In the case of the AsapStructure/Accelerator tables, this just indicates whether or not that document is approved.

For the join table, progress_status indicates whether or not that relationship has been approved.

The SQL I have generated gets close, but it selects duplicate records, it is as follows:

SELECT 

    AsapStructure.id,
    AsapAccelerator.id,
    AsapAccelerator.foreign_id,
    AsapAccelerator.title,
    AcceleratorsNode.progress_status,
    AsapAccelerator.filename,
    AsapAccelerator.filesize,
    AsapAccelerator.language,
    AsapAccelerator.doctype,
    AsapAccelerator.progress_status,
    AsapAccelerator.modified
FROM
    accelerators AS AsapAccelerator
        left JOIN
    accelerators_nodes AS AcceleratorsNode ON (AcceleratorsNode.accelerator_id = AsapAccelerator.id)
        left JOIN
    asap_structure AS AsapStructure ON (AcceleratorsNode.node_id = AsapStructure.id)
WHERE
    AsapAccelerator.progress_status = 5
ORDER BY AsapStructure.id ASC, AsapAccelerator.title ASC
LIMIT 50    

Sample Output

    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+
    | id   | id   | foreign_id | title                           | progress_status | filename                                                          | filesize | language | doctype       | progress_status | modified            |
    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+
    | NULL | 1963 |       1211 | Value Delivery Scorecard        |            NULL | 484_Value_Delivery_Status_Project_Scorecard_Template_MS_Draft.doc |   113152 | English  | Template Form |               5 | 2012-03-05 23:56:53 |
    |    1 | 1686 |        933 | Going Live Check Sample Report  |               4 | 459_SAP_GoingLive_Check_Analysis_Session_Sample_Report.doc        |   779264 | English  | Sample        |               5 | 2012-03-05 23:56:21 |
    |    1 | 1792 |       1100 | Preliminary Cutover Strategy    |               4 | 471_Preliminary_Cutover_Strategy.ppt                              |  1070080 | English  | Presentation  |               5 | 2012-03-05 23:56:33 |
    |  933 | 1686 |        933 | Going Live Check Sample Report  |               5 | 459_SAP_GoingLive_Check_Analysis_Session_Sample_Report.doc        |   779264 | English  | Sample        |               5 | 2012-03-05 23:56:21 |
    | 1100 | 1792 |       1100 | Preliminary Cutover Strategy    |               5 | 471_Preliminary_Cutover_Strategy.ppt                              |  1070080 | English  | Presentation  |               5 | 2012-03-05 23:56:33 |
    | 1151 | 1894 |       1151 | Cutover Communications          |               5 | 56_Cutover_Communications.xls                                     |   120320 | English  | Template Form |               5 | 2012-03-05 23:56:45 |
    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+

As you can see, the SECOND id column contains the ID of the Accelerator. The first id column is the ID of the AsapStructure row. You can see that there are duplicate rows in the second id field, 1686 and 1792 respectively.

The first row, you can see that the first id field is NULL, this just means that there is not a relationship between an AsapStructure row and that Accelerator.

My Goal

I want to select ALL available Accelerators, regardless of whether or not it is attached to an AsapStructure row. If it IS attached to an AsapStructure row – I ONLY want to return it if it matches XX (the Node ID of the document they are viewing and want to add attachments [Accelerators] to), otherwise return NULL.

The reason behind this, is we are displaying a paginated list, and the items in that list will display the status of the relationship, IF it exists. If it does not exist, we just give them an option to take action on that item.

Desired Result

Here is the (desired) output of the SQL query, as you can see it is selecting unique records, and also note the id‘s of the first id field.

    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+
    | id   | id   | foreign_id | title                           | progress_status | filename                                                          | filesize | language | doctype       | progress_status | modified            |
    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+
    | NULL | 1963 |       1211 | Value Delivery Scorecard        |            NULL | 484_Value_Delivery_Status_Project_Scorecard_Template_MS_Draft.doc |   113152 | English  | Template Form |               5 | 2012-03-05 23:56:53 |
    |    1 | 1686 |        933 | Going Live Check Sample Report  |               4 | 459_SAP_GoingLive_Check_Analysis_Session_Sample_Report.doc        |   779264 | English  | Sample        |               5 | 2012-03-05 23:56:21 |
    |    1 | 1792 |       1100 | Preliminary Cutover Strategy    |               4 | 471_Preliminary_Cutover_Strategy.ppt                              |  1070080 | English  | Presentation  |               5 | 2012-03-05 23:56:33 |
    | NULL | 1894 |       1151 | Cutover Communications          |               5 | 56_Cutover_Communications.xls                                     |   120320 | English  | Template Form |               5 | 2012-03-05 23:56:45 |
    +------+------+------------+---------------------------------+-----------------+-------------------------------------------------------------------+----------+----------+---------------+-----------------+---------------------+

This way, when we iterate over the data, we can easily determine:

  • If it is bound to a document
  • IF it is bound to a document, then we can determine the status of that relationship.

If there is an easier way to do this, I would love to hear it!

  • 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-31T17:14:26+00:00Added an answer on May 31, 2026 at 5:14 pm

    Did you try grouping by accelerator id?

    SELECT 
    
        AsapStructure.id,
        AsapAccelerator.id,
        AsapAccelerator.foreign_id,
        AsapAccelerator.title,
        AcceleratorsNode.progress_status,
        AsapAccelerator.filename,
        AsapAccelerator.filesize,
        AsapAccelerator.language,
        AsapAccelerator.doctype,
        AsapAccelerator.progress_status,
        AsapAccelerator.modified
    FROM
        accelerators AS AsapAccelerator
            left JOIN
        accelerators_nodes AS AcceleratorsNode ON (AcceleratorsNode.accelerator_id = AsapAccelerator.id)
            left JOIN
        asap_structure AS AsapStructure ON (AcceleratorsNode.node_id = AsapStructure.id)
    WHERE
        AsapAccelerator.progress_status = 5
    GROUP BY AsapAccelerator.id
    ORDER BY AsapStructure.id ASC, AsapAccelerator.title ASC
    LIMIT 50    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know if there are any mechanism in Akka that can have
I seem to remember that Regular Expressions in DotNet have a special mechanism that
I have some event handler on a boundary class that manages a persistence mechanism
I have a control and it provides a selection mechanism. However, the items that
I'm writing a web based application that will have its own authorization/authentication mechanism (traditional
I have a mechanize script written in python that fills out a web form
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a queuing mechanism in C on Unix. It accepts XML transactions. Some
So I have a PHP proxy that gets information from a website. Let's say
I have a voting mechanism on the site. When people vote up or down,

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.