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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:03:34+00:00 2026-05-26T09:03:34+00:00

While executing join query I am getting duplicate data instead of the distinct keyword.

  • 0

While executing join query I am getting duplicate data instead of the “distinct” keyword. I dim much more google and gained nothing. The table names are “Event” which holds list of events and the other table is UserEvents which assgins vents to users. On event can be assigned to multiple users. I am using SQL server 2005.

Events
eid | ename
-----------------
e1  | Test event1
e2  | test ecent2

UserEvents
id| uid |  eventId
-----------------
1 | u1  |  e1
2 | u1  |  e2
3 | u2  |  e1

Query:

select distinct 
Events.eid, Events.ename,UserVents.uid  
  from
      Events
  inner join
      UserEvents on
      UserEvents.eventID=Events.eid

Output:

eid | ename       | uid
-------------------
e1  | Test event1 | u1
e2  | Test event2 | u2
e1  | test event1 | u1

Issue:

Here, Event is repeating instead of the distinct key word. It should not repeat the event ‘e1″.
Kindly help me. How I change the query? Is this an issue in SQL server 2005??
kinly help

  • 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-26T09:03:35+00:00Added an answer on May 26, 2026 at 9:03 am

    DISTINCT applies to the whole column list. The whole row needs to be the same to be eliminated.

    The results you have put in your question are not complete as you have missed out the uid column.

    WITH Events(eid,ename) AS(
    SELECT 'e1' ,'Test event1' UNION ALL
    SELECT 'e2' ,'test ecent2')
    
    ,UserEvents(id,uid,eventId) AS
    (
    SELECT 1,'u1' , 'e1' UNION ALL
    SELECT 2,'u1' , 'e2' UNION ALL
    SELECT 3,'u2' , 'e1'
    )
    select distinct 
            Events.eid, Events.ename,UserEvents.uid  
            from
            Events
            inner join
            UserEvents on
            UserEvents.eventId=Events.eid
    

    Returns

    eid  ename       uid
    ---- ----------- ----
    e1   Test event1 u1
    e1   Test event1 u2
    e2   test ecent2 u1
    

    None of the rows are the same.

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

Sidebar

Related Questions

What I want to do is while executing MySQL query, passing column data into
I am getting the following error while executing the following query in an Stored
while executing the following query, i get an error that there's an error in
in DB2 while executing a query i got SqlException: DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016
I have encountered a strange behavior while executing an sql query on the Oracle
I am getting WatiN.Core.Exceptions.TimeoutException : Timeout while Internet Explorer busy error while executing my
I am executing this statement under while (($data=fgetcsv($this->fin,5000,;))!==FALSE) Now what I want in else
While using inner join on Pro*C I am getting the below error: PCC-S-02201, Encountered
I have a problem while executing a SSIS script component. To be honest I
Is there any tool that enables you to hot swap JavaScript contents while executing

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.