Tuesday, 15 June 2010

Looking up names in other tables(SQL) -



Looking up names in other tables(SQL) -

i have 2 tables

applied_uni

studentid university1code university2code university3code 1 u1 u2 u3 2 u1 u2 u4

university

universitycode universityname u1 school1 u2 school2 u3 school3 u4 school4

the problem i'm having don't know how write sql select students university names applied into.

any kind help appreciated.

you need bring together on itself:

select au.studentid, u.universityname name1, u2.universityname name2, u3.universityname name3 applied_uni au left bring together university u on au.university1code = u.universitycode left bring together university u2 on au.university2code = u2.universitycode left bring together university u3 on au.university3code = u3.universitycode

alternatively, should work:

select au.studentid, u.universityname applied_uni au left bring together university u on au.university1code = u.universitycode or au.university2code = u.universitycode or au.university3code = u.universitycode

sql

No comments:

Post a Comment