How to sort that does not include duplicates in display?

Hi everybody,
   I like to asked anyone who is very good at sql to help me display this data in a table

format that duplicate headings, subheadings or other columns won't appear twice or more. Can anyone help me I need to sort them and load them in a Datatable. Loop thorugh all records and display them in a label control created at run time. Thanks in advance.

Sample Data:

Topics Table
TopicId  TopicLevel  Topic          ParentId
1           1        First             0
2           1        AnotherFirst      0
3           2        Second            1
4           2        AnotherSecond     2
5           3        Third             3

Contents Table
ContentID  Heading       SubHeading SubSubHeading1 NumberText Names Content1     ParentId
1          How are you   Hello      Someone            1       Ben   some text   5
2    How are you   Hello      Someone            1       John  other text   5
3          How are you   Hello      Anybody            2       Ben   some text    5
4          How are you   Hello      Anybody            2       Mike   other text   5
5          How are you   Greet      Anywhere           1       Ben   some text     5
6          How are you   Greet      Anywhere           1       Luke   some text     5
7          I miss you.   Really     When              null     null   some text     5
8          I miss you.  Really      When              null     null   some text     5

Display Format:
          How are you
----------------------------------------------
              Hello
-----------------------------------------------
1    Someone
----------------------------------------------
   Ben                some text
---------------------------------------------
   John               other text
---------------------------------------------
2    Anybody
---------------------------------------------
   Ben                some text
---------------------------------------------
   Mike               other text
--------------------------------------------
               Greet
-------------------------------------------------  
1  Anywhere
-----------------------------------
   Ben                some text
-------------------------------------
   Luke               some text
================================================
             I miss you
--------------------------------------------------
                Really
------------------------------------------------
    When
-----------------------------------------------
                       some text
----------------------------------------
                       some text
------------------------------------------


den2005



Answer this question

How to sort that does not include duplicates in display?

  • Michael Drüing

    Thanks for replying, Blair.

       Yes, you can say I used force to just to get the format require to diplsya the data without duplicates from the table structure I have.

     

    dennis


  • _wim

    SQL is not suited for generating formatted reports. You could do it but it will look ugly and require dynamic SQL etc. You should return the data to the client as is and generate the report on the client side. You can use say reporting services or crystal reports or whatever tool that the client development tool has to offer. It is very easy to generate reports with any of the reporting tools/designers.

  • OscarMarquez

    You can specify an ORDER BY clause in the SELECT statement that retrieves data from Contents table. The part that is tough to do in SQL is to suppress repeating values in a column, changing column names etc.

  • Bengab

    Thanks for reply, Umachandar.

    You are saying there is no possible way to sort this data at sql side before loading it to a data object like dataset or datatable I am using Reporting services or Crystal report to display this data. I will used this data to display them in a label controls, position them  at runtime, meaning label controls are created at runtime.

    den2005

     


  • indiana_c

    Hi Umachandar,

      I don't think that will work using Order by alone. Duplicates will still be shown. Thanks for reply.

     

    den2005


  • Tom Forsyth

    See:  'Eliminating Duplicates with DISTINCT'  in BOL.

     

    Rollin

     


  • TGunthorpe

    well the quick way is if the data model were correct to begin with. Because your data is not 'normal', it requires brute force to get in the form you desire.

  • Flatscher Markus

    Hi Rollin,

        I know that but I will using a lot of that, I am looking for a shorter way to do this. You are saying to use like this.

    1: Select Distinct Heading From Topics

    Then the result from first would be a fiter for next sql statement:

    2: Select Distinct SHeading From Topics Where Heading=@heading << supply data

    Then the result from second would be a fiter for next sql statement:

    3: Select Distinct SSHeading From Topics Where SHeading=@sheading << supply data

    Then so on and so forth.

    Alll this in a loop and calling and excuting the sql repeatedly. I like to avoid that.

     

    den2005

     


  • mesanjeeb

    Thanks for reply Blair. Right now, the report option is not considered, basically I want to display the contents(data) of particular table in a labels for each data inside a panel at runtime, the problem is duplicate data is being displayed as well. I want to filter them. I konw using Crystal Report would be easier than building this display at run time.

    den2005

     


  • franjorge

    den. . . its an issue of reporting not programming. . .

    here . . .  get this access database:

    http://www.obj-tec.com/MSDNForums/reportsforden2005/db1.zip

    your data is in table foo. . . there is a report called report1.

    look at the report design. note the grouping headers.

    any reporting tool should be able to do this for you.



  • Jon77

    Then you can build a hierarchal typed dataset that normalizes your data

  • Iddie

    Hi Allen

      Thanks for reply, It sounds a lot of work, does not know how to exactly do that, seems complex. Hierarchal typed dataset, what is that like multi-dimensional Please clarify.

    den2005


  • Sashidhar Kokku

    typed dataset is a .Net construct. ask in the .Net data access forum

     



  • basementjack

    Hi Blair,

        I used the long approach of using a lot select Distinct queries and use a lot of loop to get next dsitinct column and so on and so forth. It seems there is short approach to this issue right now in .Net.

     

    den2005


  • How to sort that does not include duplicates in display?