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

  • Home
  • SEARCH
  • 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 3349038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:36:56+00:00 2026-05-18T01:36:56+00:00

Our customer feeds us contracts with duplicate items. We advertise unique products. How could

  • 0

Our customer feeds us contracts with duplicate items. We advertise unique products. How could I select a distinct set of upcs with descriptions without doing many sub queries? Horrible example:

/* 
eventID     int
groupID     int            // This field is different between fields
upc_ean     numeric(18,0)
description varchar(512)   // Description is slightly different but same info
size        varchar(512)   // Size is slightly different but same info
*/

select A.eventid, A.upc_ean,

       ( select top 1 description 
         from myTable B 
         where B.eventid = A.eventid and B.upc_ean = A.upc_ean) as description,

       ( select top 1 size
         from myTable B
         where B.eventid = A.eventid and B.upc_ean = A.upc_ean) as size

from ( select distinct eventid, upc_ean from myTable) A

Is there any way to do the same thing without sub-queries, somehow joining the two together that doesn’t breed records or show duplicates using eventid and upc_ean as a PK?

  • 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-18T01:36:57+00:00Added an answer on May 18, 2026 at 1:36 am

    You can add an ORDER BY clause if necessary to the OVER portion of the following if necessary.

    Using a CTE:

    WITH example AS (
      SELECT a.eventid, 
             a.upc_ean,
             a.description,
             a.size,
             ROW_NUMBER() OVER(PARTITION BY a.eventi, a.upc_ean) AS rank
        FROM YOUR_TABLE a)
    SELECT x.eventid,
           x.upc_ean,
           x.description, 
           x.size
      FROM example x
     WHERE x.rank = 1
    

    Without the CTE:

    SELECT x.eventid,
           x.upc_ean,
           x.description, 
           x.size
      FROM (SELECT a.eventid, 
                   a.upc_ean,
                   a.description,
                   a.size,
                   ROW_NUMBER() OVER(PARTITION BY a.eventi, a.upc_ean) AS rank
              FROM YOUR_TABLE a) x
     WHERE x.rank = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our customer advertises products but the product's attributes are vastly different from one another.
Our customer would like to know who is online and currently using the custom
I am considering adding OpenID to our customer facing admin and control panel areas...
We're doing a complex bit of data accumulation. Our customer sends us some stuff
I would really like to use SpringSource dm Server, but our customer requires us
Our marketing department comes back with active directory integration being a key customer request,
In our program, each customer gets their own database. We e-mail them a link
The customer wants us to log the actions that a user performs on our
We have a customer that is trying to call our web service written in
We're in the process of redesigning the customer-facing section of our site in .NET

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.