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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:02:26+00:00 2026-05-20T05:02:26+00:00

Error in group by clause :: I want make records unique in MS sql.here

  • 0

Error in group by clause ::
I want make records unique in MS sql.here i have used 2-3 tables join and when clause.
it is more difficult to make it distinct by using group by clause it gives error like..

Error :::: Incorrect syntax near the keyword 'GROUP'

select * from(
    SELECT TOP 5 m.pk_member_id,m.first_name+' '+m.middle_name+' '+m.last_name as "NAME", 
    m.gender AS "GENDER",
    datediff(Year,m.date_of_birth, getdate()) AS "AGE", 
    m.home_email AS "EMAIL", 
    m.business_phone AS "PHONE1", 
    m.cell_phone AS "PHONE2", 
    m.address+','+m.city+','+m.state+','+m.zip_code AS "ADDRESS", 
    paidamt = 
            CASE WHEN (moi.credit_card_amt!=null or moi.credit_card_amt > 0) THEN moi.credit_card_amt 
                 WHEN (moi.cheque_amt!=null or moi.cheque_amt > 0) THEN moi.cheque_amt 
                 WHEN (moi.debit_card_amt!=null or moi.debit_card_amt > 0) THEN moi.debit_card_amt 
                 WHEN (moi.cash_amt!=null or moi.cash_amt > 0) THEN moi.cash_amt 
            END, 
    mode = 
            CASE WHEN (moi.credit_card_amt!=null or moi.credit_card_amt > 0) THEN 'CREDIT CARD' 
                   WHEN (moi.cheque_amt!=null or moi.cheque_amt > 0) THEN 'CHEQUE' 
                   WHEN (moi.debit_card_amt!=null or moi.debit_card_amt > 0) THEN 'DEBIT CARD' 
                   WHEN (moi.cash_amt!=null or moi.cash_amt > 0) THEN 'CASH' 
            END, 
    m.registration_date as "JOINING DATE", 
    m.membership_expiry_date as "EXPIRY DATE", 
        services = 
                CASE WHEN m.pk_member_id=em.fk_member_id THEN 'EVENT' 
                         WHEN m.pk_member_id=dm.fk_member_id THEN 'DINING' 
                         WHEN m.pk_member_id=jm.fk_member_id THEN 'JF2' 
                END 
        FROM 
        Member m, 
        Member_Official_Info moi, 
        Event_Members em, 
        Dining_Members dm, 
        JF2_Members jm 
        WHERE 
        m.pk_member_id = moi.fk_member_id and 
        (m.pk_member_id = em.fk_member_id or m.pk_member_id = dm.fk_member_id or m.pk_member_id = jm.fk_member_id) and 
        YEAR(m.membership_expiry_date)=2008
        )
        GROUP BY 
        m.pk_member_id,m.first_name,m.middle_name, m.last_name,m.business_phone,m.cell_phone,m.address,m.city,\
        m.state,m.zip_code,m.gender,m.date_of_birth,m.home_email,m.registration_date, 
        m.membership_expiry_date,services,paidamt,mode;
  • 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-20T05:02:27+00:00Added an answer on May 20, 2026 at 5:02 am

    just going into details on some of the issues with this:

    change your from clause in the sub query to something like this:

    from Member m
        inner join Member_Official_Info moi
            on m.pk_member_id=moi.fk_member_id
        left outer join Event_Members em
            on m.pk_member_id=em.fk_member_id
        left outer join Dining_Members dm
            on m.pk_member_id=em.fk_member_id
        left outer join JF2_Members jm
            on m.pk_member_id=em.fk_member_id
    

    i’m guessing, like everyone else, that this’ll probably remove the need for your group by clause

    i’d also change your where clause in the subquery to this:

    where m.membership_expiry_date>='1/1/2008'
        and m.membership_expiry_date<'1/1/2009'
    

    Also, i’d change your paidamt and mode code to something like this:

    case when coalesce(moi.credit_card_amt,0)>0 then moi.credit_card_amt
        when coalesce(moi.cheque_amt,0)>0 then moi.cheque_amt
        case when coalesce(moi.debit_card_amt,0)>0 then moi.debit_card_amt
        case when coalesce(moi.cash_amt,0)>0 then moi.cash_amt
    

    Also, there’s inconsistancy with your column aliasing. in certain points your using Column Name=, or you’re using as “Column Name”, or even as [Column Name]. This is rather confusing, so i’d pick one way to alias columns and stick with it.

    Also, if fixing the joins works and doesn’t require you to do the group by, then move everything out of the subquery cause there’s no need for it

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

Sidebar

Related Questions

I'm getting an error here that says I haven't defined a method, but it
I would like to update my SQL lite database with the native update-method of
I have a new web app that is packaged as a WAR as part
I have a snippet to create a 'Like' button for our news site: <iframe
We manage a site for a medical charity. They have a number of links
I'm trying to write test harness for part of my Android mapping application. I
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME
I'm trying to build a C++ extension for python using swig. I've followed the

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.