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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:16:04+00:00 2026-05-12T21:16:04+00:00

A few weeks ago I asked a question about eliminating duplicate records in a

  • 0

A few weeks ago I asked a question about eliminating duplicate records in a SQL INNER JOIN. The code I ended up using is similar to the following answer:

SELECT ROW_NUMBER() OVER(ORDER BY " + orderField + @") AS RowNum,
       mt.ID AS mt_ID,
       mt.title AS mt_title,
       [...]
       MAX(st.title) AS st_title,
       -- Other aggregates (MAX, MIN, AVERAGE, ...) for all other columns
       -- from sttable, whatever is appropriate.
       [...]
FROM mttable AS mt 
INNER JOIN sttable AS st on mt.ID =st.ID
WHERE st.field <> 0 AND mt.title = @title
GROUP BY mt.ID,
         mt.title
         -- Group by everything else from mttable.

This works well enough at eliminating duplicates, but the problem I have now is that I want to perform queries on sttable (the table that is not grouped), and the GROUP BY eliminates this data. For example, I want to be able to run the query WHERE st.title = '...'

Is there any way I can achieve this? 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-05-12T21:16:05+00:00Added an answer on May 12, 2026 at 9:16 pm

    Try using a CTE (common table expression) that will first define the data you want to get from the sttable table – in the CTE, filter, join, group, etc. on whatever you want to do within the sttable table. Not sure if this will work specifically for what you are trying to do, but it most likely will. If you can provide some additional detail on what you are trying to do (i.e. what are you wanting to do specifically within sttable, filter on certain fields, etc.).

    Would look something like this:

    with stData as
    (
        select  st.ID, st.field
        from    sttable st
        where   st.field <> 0
        -- Add additional filters here
        and st.someOtherField = something
    )
    SELECT ROW_NUMBER() OVER(ORDER BY orderField) AS RowNum,
           mt.ID AS mt_ID,
           mt.title AS mt_title,
           MAX(st.title) AS st_title,
           -- Other aggregates (MAX, MIN, AVERAGE, ...) for all other columns
           -- from sttable, whatever is appropriate.
    FROM mttable AS mt 
    INNER JOIN stData AS st 
    on mt.ID =st.ID
    WHERE st.field <> 0 
    AND mt.title = @title
    GROUP BY mt.ID,
             mt.title
             -- Group by everything else from mttable.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few weeks ago i asked a question about a multilanguage site (see Multilanguage
A few weeks ago I asked exactly the same question here . At first,
A few weeks ago, I was able to build Apps using py2app. I just
I've started learning Objective-C a few weeks ago and I still don't understand how
I am going back though a web-based document numbering system from few weeks ago.
I'm not certain when this problem started occuring, but it was approximately a few
I have a strange problem when I try to deploy my current app to
I have been building a Rails application that performs accounting functionality. As part of
I'm strongly considering adding unit testing to an existing project that is in production.
In Hudson we have a job that deploys a specified subversion tag to a

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.