Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    11

    Unanswered: help needed building weird query :)

    hi! i'm actually sort of newbie in this whole database world, but i have learned enough to somewhat defend myself, but i have come upon a situation where i cant think of a way to retrieve the data the way i need it, i just found out this forum existed and i think it's just great!

    ok my real problem, i'll describe with a simplier example
    lets say i have the following tables:

    create table names(
    id serial PRIMARY KEY,
    name text
    );

    create table x(
    x1 integer REFERENCES names (id),
    x2 integer REFERENCES names (id),
    x3 integer REFERENCES names (id)
    );

    so... my names table is populated with

    id | name
    -----------
    1 | name1
    2 | name2
    3 | name3
    4 | name4
    5 | name5

    and my x table contains the following:

    x1 | x2 | x3
    --------------
    2 | 3 | 5
    1 | 4 | 2


    now, what i need is to make a query similar to:
    select name from names,x where x.x1=names.id;


    but the tricky thing is that i need to list the 3 names
    for example for the first row of the x table (2, 3,5), i would need to get a list looking like this:

    name | name | name
    ----------------------------
    name2 | name3 | name5




    i have tried a lot of combinations of queries but havent succeded, the closest i get is

    name
    --------
    name2
    name3
    name5


    if this is not possible let me know so i can stop trying
    Last edited by bitar; 12-23-03 at 13:35.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002

  3. #3
    Join Date
    Jan 2004
    Posts
    26
    I don't know and I can't imagine why are you needing something like that.

    I've seen that you had an answer but I still want to make you an advice. That kind of solutions are sometimes very problematic. Sooner or later you will have to meke a change. It's better soon.
    That kind of solution let's you out of inserting new records or colums without rebuilding the query.

  4. #4
    Join Date
    Dec 2003
    Posts
    11
    hehe i already changed the way i'll access the data, but thanks anyway!!

Posting Permissions

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