Results 1 to 3 of 3

Thread: Query help

  1. #1
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76

    Unanswered: Query help

    I have a table that has the following data:
    id | name | value | data
    -----------------------------------
    1 | jay | 30 | 9
    2 | jay | 30 | 9
    5 | yusuf | 45 | 2
    12 | dick | 90 | 3
    98 | scott | 30 | 9
    99 | scott | 30 | 9

    Notice, that the rows with id = 1 and 2 (has the same values), so does rows with id = 98 and 99. I want to write a query that'll return the first occurence of each row that has distinct name, value and data. That is, removes duplicated data.

    so that I'll get:

    id | name | value | data
    -----------------------------------
    1 | jay | 30 | 9
    5 | yusuf | 45 | 2
    12 | dick | 90 | 3
    98 | scott | 30 | 9

    Actually, in my application I only need the ids so

  2. #2
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76
    forget it,

    I could use:
    select min(id), name,value, data from tbl group by name,value,data;

  3. #3
    Join Date
    Apr 2003
    Location
    Tunisia
    Posts
    192

    Thumbs up U could do this

    U have to write a function that gets the id as input and thougout the data of that row would compare it with the rest of the rows , the output would be the nbr of occurence of that row or just the id of the duplicated data, It should be like this

    CREATE or REAPLCE FUNCTION occ(id_start) RETURNS int2 as '
    [Treatment: a good select]'

    Than just call it via query =>
    karim2k=# select occ(1) from Mytable;
    occ
    -----
    2
    (1 row)

    If u face problems I'll write the entire function for you !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •