locked
Hide duplicates in tables only RRS feed

  • Question

  • User954998566 posted

    Hi, 

    I have a dataset select distinct values like this 

    1 john     USA    MA
    1 john     USA    AZ
    1 john     USA    TX
    2 Bob      USA   CA
    2 Bob      USA   NY
    3 Mike     USA   MN

    I populate a table with 3 columns only from this dataset

    so the result is

    1 john     USA   
    1 john     USA   
    1 john     USA   
    2 Bob      USA  
    2 Bob      USA  
    3 Mike     USA  

    How can I show in this table distinct result like this

    1 john     USA   
    2 Bob      USA  
    3 Mike     USA 

    ?

    Thanks

    Tuesday, March 4, 2014 10:57 PM

Answers

  • User1140095199 posted

    Hi,

    salim20001

    How can I show in this table distinct result like this

    1 john     USA   
    2 Bob      USA  
    3 Mike     USA 

    I created a Demo Table . Just make sure that you get the column names are correct when you use the query for the table:

    The Table Data:

    The Sequel Code:

    The trick is to use the Row_Number( ) to get the first column.

    select ROW_NUMBER() over (order by Name)
    as Slno, Name,Country from Info group by Name,Country 

    Result:

    It's a working solution!

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 6, 2014 3:41 AM

All replies

  • User724169276 posted

    Hello Salim,

    try this:

    SELECT ID, Name, Country
    FROM tblname
    GROUP BY ID, Name

    Tuesday, March 4, 2014 11:02 PM
  • User1140095199 posted

    Hi,

    salim20001

    How can I show in this table distinct result like this

    1 john     USA   
    2 Bob      USA  
    3 Mike     USA 

    I created a Demo Table . Just make sure that you get the column names are correct when you use the query for the table:

    The Table Data:

    The Sequel Code:

    The trick is to use the Row_Number( ) to get the first column.

    select ROW_NUMBER() over (order by Name)
    as Slno, Name,Country from Info group by Name,Country 

    Result:

    It's a working solution!

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 6, 2014 3:41 AM