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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:03:23+00:00 2026-06-10T00:03:23+00:00

I have a table that contains the following columns; a, b, e and another

  • 0

I have a table that contains the following columns; a, b, e and another table, table2 that contains c,d. Both tables have a column name.

I made a query:

SELECT distinct a, b
from db.table
where e <>'65';

And I got say, 1885 records

Then, I needed more information from another table (c, d). I used inner join to get these additional information. The query becomes:

SELECT distinct a, b, c, d 
from db.table
inner join db.table2
on table.name=table2.name2
where e <>'65';

Now, I was expecting the same result but with additional columns (c, d). But I got a different number of results: 51144. Can any body explain please why the number increased while I just added more columns and did not change the condition ?

  • 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-10T00:03:24+00:00Added an answer on June 10, 2026 at 12:03 am

    DISTINCT returns as the key word says, the distinct results from the select.

    The fact that you are adding additional columns to the distinct select will possibly cause the distinct result set to be more rows. Lets have a look at an example

    Distinct from

    A   B
    1   2
    1   3
    1   2
    

    would be

    A   B
    1   2
    1   3
    

    but now adding additional columns to this, let say

    A   B   C
    1   2   1
    1   3   2
    1   2   3
    

    will result in

    A   B   C
    1   2   1
    1   3   2
    1   2   3
    

    Further more, your inner join can limit the result set, as inner join will only return values that are in both table1 and table2, so it a given value is present in table1, but not in table2 it will not be returned.

    Or as was mentioned by @zerkms, if there were 2 keys defining the relationship between the 2 tables, you might get more that you expected.

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

Sidebar

Related Questions

I have a table that contains the following columns: @Column(name=CTDESTATUS) private String status; @Column
I have two tables say Table1 and Table2 that contains the following column with
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have the following requirement. I have a table with a column that contains
I have a T-SQL table that contains the following columns: Date, StationCode, HDepth, and
I have a table in SQL Server that contains the following columns : Id
I have a table that contains common entries in two columns. For Example: Column1
I have a table that contains a record of prioritys that links to another
I have a table that contains an Id column as a primary key. There
I have a table which contains the following columns: UniqueID remote_ip_addr platform I want

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.