Please help, how to return records by one copy from DB where records are by 2 or more

Discussion in 'C#' started by jusa, Aug 11, 2008.

  1. #1
    how to return the list of records by one copy from the database where the records are by two or more copies i. e.
    if the records are 1, 1, 2, 2, 2, 3, 4, 4, 4, 4 in a DB column, so i want it to be returned only by one copy as below
    1
    2
    3
    4

    i'm using the script below
    [
    dim q
    q="select ddate from ddate_table"
    dim r
    set r=c.execute(q)
    do while not r.eof
    %>
    <td><tr><%=r("ddate")%></td></tr>
    <%
    r.movenext
    loop
    ]
     
    jusa, Aug 11, 2008 IP
  2. jdkjdk

    jdkjdk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the sql you need is

    select unique(ddate) from ddate_table
     
    jdkjdk, Aug 11, 2008 IP
  3. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #3
    select distinct ddate from ddate_table
     
    vihutuo, Aug 12, 2008 IP
  4. engager

    engager Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    and finally

    select ddate from ddate_table group by ddate

    is also acceptable))
     
    engager, Aug 14, 2008 IP
  5. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #5
    A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs.
    GROUP BY should be used to apply aggregate operators to each group. If all you need is to remove duplicates then use DISTINCT. If you are using sub-queries execution plan for that query varies so in that case you need to check the execution plan before making decision of which is faster.


    HTH
    Regards :)
     
    yugolancer, Aug 14, 2008 IP
  6. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    If you ask yourself which one is more efficient then i assure that their performance is usually identical.
    It is up to you which one you will use. I would say that is in only a matter of taste. :)
     
    yugolancer, Aug 14, 2008 IP