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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:56:43+00:00 2026-06-13T22:56:43+00:00

Please consider the following simplified MySQL table: id | docID | docTypeID | makeID

  • 0

Please consider the following simplified MySQL table:

id  | docID  | docTypeID | makeID | desc
1   | 1      | 1         | 1      | doc 1
2   | 1      | 1         | 2      | doc 2
3   | 2      | 2         | 1      | doc 3
4   | 3      | 3         | 2      | doc 4
5   | 1      | 1         | 4      | doc 5
6   | 2      | 2         | 5      | doc 6
7   | 4      | 1         | 1      | doc 7

In this example docID, docTypeID, and makeID are all foreign keys.

When a doc of docTypeID 1 is associated with multiple makes, I need to group those docs together and return a special make description (‘multiple makes found’).

What I need to return for this example table would be:

id  | docID  | docTypeID | makeID                | desc
1   | 1      | 1         | multiple makes found  | doc 1
3   | 2      | 2         | 1                     | doc 3
4   | 3      | 3         | 2                     | doc 4
6   | 2      | 2         | 5                     | doc 6
7   | 4      | 1         | 1                     | doc 7

Note that in the case of id 7, only a single make is found so there is no grouping performed.

I’m not sure how to limit grouping based on criteria or if that is even possible. I’m hopeful one of the SQL geniuses here can assist. Please let me know if any additional info is required. Thanks.

  • 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-13T22:56:44+00:00Added an answer on June 13, 2026 at 10:56 pm

    You can write:

    SELECT MIN(id) AS id,
           docID,
           docTypeID,
           CASE WHEN COUNT(1) > 1
                THEN 'multiple makes found'
                ELSE MIN(makeID)
            END AS makeID,
           MIN(desc) AS desc
      FROM simplified_mysql_table
     GROUP
        BY docID,
           docTypeID
           CASE WHEN docTypeID = 1
                THEN 0
                ELSE id
            END
    ;
    

    (N.B. The MIN(id) and MIN(desc) may not come from the same underlying record. If that’s a problem, then you’ll need to tweak the above a bit.)

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

Sidebar

Related Questions

Please consider following tables. Table: Document docID, docNr, docScanTime 10, 99, 2012-08-02 11, 98,
Please consider the following simplified example: #include boost/shared_ptr.hpp #include boost/smart_ptr/enable_shared_from_this.hpp using namespace boost; class
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Please consider the following table (created using a corresponding entity) request ------- id requestor
Please consider the following HTML: <td> Some Text <table>.....</table> </td> I need to manipulate
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Please consider the following example struct Foo { int bar; Foo(int i):bar(i){cout << real

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.