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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:55:20+00:00 2026-06-14T02:55:20+00:00

I having a challenge with my query returning multiple results. SELECT DISTINCT gpph.id, gpph.cname,

  • 0

I having a challenge with my query returning multiple results.

SELECT DISTINCT gpph.id, gpph.cname, gc2a.assetfilename, gpph.alternateURL
FROM [StepMirror].[dbo].[stepview_nwppck_ngn_getpimproducthierarchy] gpph 
INNER JOIN [StepMirror].[dbo].[stepview_nwppck_ngn_getclassification2assetrefs] gc2a
ON gpph.id=gc2a.id
WHERE gpph.subtype='Level_4' AND gpph.parentId=@ID AND gc2a.assettype='Primary Image'

result set

A record, 5679599, has 2 ‘Primary Images’ and is returning 2 results for that id but I only need the first result back. Is there any way to do this IN the current query? Do I need to write multiple queries?

I need some direction on how to constrain the results to only 1 result on Primary Image. I have looked at a ton of similar questions but most typically are just requiring the guidance of adding ‘distinct’ to the beginning of their query rather than on the where clause.

Edit: This problem is created by a user inputting 2 Primary Images on one record in the database. My business requirements only state to take the first result.

Any help would be awesome!

  • 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-14T02:55:21+00:00Added an answer on June 14, 2026 at 2:55 am

    Given the choice is arbitary which to return, we can just use an aggregate on the value. This then needs a group by clause, which eliminates the need for the distinct.

    SELECT gpph.id, gpph.cname, max(gc2a.assetfilename), gpph.alternateURL
    FROM [StepMirror].[dbo].[stepview_nwppck_ngn_getpimproducthierarchy] gpph 
    INNER JOIN [StepMirror].[dbo].[stepview_nwppck_ngn_getclassification2assetrefs] gc2a
    ON gpph.id=gc2a.id
    WHERE gpph.subtype='Level_4' AND gpph.parentId=@ID AND gc2a.assettype='Primary Image'
    GROUP BY gpph.id, gpph.cname, gpph.alternateURL
    

    In this instance, using max(gc2a.assetfilename) is going to give you the alphabetically highest value in the event of there being more than one record. It’s not the ideal choice, some kind of timestamp knowing the order of the records might be more helpful, since then the meaning of the word ‘first’ could make more sense.

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

Sidebar

Related Questions

I'm having quite a challenge creating an appropriate rewrite rule for Apache/2.2.14 on Fedora
I'm having quite a challenge... I have a web page where the user clicks
I'm having trouble trying to figure out how to achieve this programming challenge in
I'm having a first painful experience with postgresql, and the minute-challenge of the moment
I'm doing some modifications to a wordpress theme, but I'm having a challenge removing
Am having a bit of challenge in laying out my form using sizers in
LIVE CODE: http://jsfiddle.net/vy4nY/ I'm following this challenge , but I'm having some issues. I'm
I am having a challenge. I have 2 divs , one set to display:none;
I'm having a challenge with sending emails with arabic content using PHP's mail function.
I'm new to vb.net and having quite a challenge with updating a field in

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.