SQL issue

Discussion in 'MySQL' started by protocol96, Apr 22, 2007.

  1. #1
    i am facing as issue, here's my database (an example;) )
    id class name
    1 class1 jon
    2 class1 mac
    3 class1 jim
    4 class1 suzy
    5 class1 ryan
    1 class2 aron
    2 class2 kaz
    3 class2 taz
    4 class2 jazz
    1 class3 raffy
    2 class3 taffy
    3 class3 tammy
    4 class3 jammy
    5 class3 yammy

    now i want the results to be displayed as

    1 class1 jon | class2 aron | class3 raffy
    2 class1 mac | class2 kaz | class3 taffy
    3 class1 jim | class2 taz | class3 tammy
    4 class1 suzy | class2 jazz | class3 jammy
    5 class1 ryan | |||||||||| | class3 yammy

    i tried using joins of all kinda, i was able to kinda get the structure though but i was missing out the fifth element which is wat i wanted as i need to identify if theres a missing person in any class. The database is pretty huge.

    the sql statement i used was,

    but like i said, using this the fifth element goes out missing, wat i need is soace or null or anything which indicates a missing person in a class.

    Help appreciated.
     
    protocol96, Apr 22, 2007 IP
  2. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is the question too dumb or too tough?
     
    protocol96, Apr 23, 2007 IP
  3. m1l

    m1l Active Member

    Messages:
    101
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    You didn't say which DB, so in Oracle something like this would bring back the results.

    select c1.class || ' ' || c1.name class_1 || ' | ' ||
    c2.class || ' ' || c2.name class_2 || ' | ' ||
    c3.class || ' ' || c3.name class_3
    from tbl1 c1,
    tbl2 c2,
    tbl3 c3
    where c1.class = 'class1'
    and c2.class = 'class2'
    and c3.class = 'class3'
     
    m1l, Apr 24, 2007 IP
  4. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #4
    Being a SQL issue it might be MS SQL (Windows) or MySQL (*Nix), that's the point :rolleyes:
     
    Mystique, Apr 24, 2007 IP