self join rows into one row

  • I have a table that has fields:
     
    FName LName MName Phone Age Location
    meeee  uggly  ooooo  00001        KS
    meeee  uggly  nnnnn           088  
    meeee  uggly  uuuuu  00003                 

    meeee  uggly  ooooo           077
    meeee  uggly  nnnnn  00002        TX  
    meeee  uggly  uuuuu           099  NV 
     

    How can i join create a query that can join the the 6 records into something like this?
     

    FName LName MName Phone Age Location
    meeee  uggly  ooooo  00001 077  KS
    meeee  uggly  nnnnn  00002 088  TX
    meeee  uggly  uuuuu  00003 099   NV   

     
     
    thanks in advance...
  • not sure if you can count on the first 3 columns acting as keys, but something like this might work:

     

    select sub.name,sub.lname, sub.mname,subAge.age,subPhone.phone,subLocation.location from

    (select name,lname, mname from

    group by name,lname)sub,

    (select name,lname,Phone from

    where phone is not null)subPhone,

    (select name,lname, Age from

    where age is not null)subAge

    (select name,lname,Location from

    where location is not null)subLocation

    where (sub.name=subPhone.name and sub.lname=subPhone.lname)

    and   (sub.name=subAge.name and sub.lname=subAge.lname)

    and   (sub.name=subLocation.name and sub.lname=subLocation.lname)

    ..also note return of records on above example is where a record is found for all 3 data columns, joins could be changed to refelct different needs

  • Look good.  Thanks..

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply