I have 1 table, with fields named: class_code, name1, class_code1, name2, class_code2. I would like to search the value of class_code, and display it as class_code and name only, where class_code = class_code1 or class_code = class_code2. The results will display class_code and name
Is this possible using sql join syntax?
This is the table:
class_code name1 class_code1 name2 class_code2 C0001 John C0002 Ben C0001 C0002 Ren C0001 Elizh C0002 C0001 Jeff C0001 Harry C0001
The output I need is:
class_code name C0001 Ben C0002 Elizh C0001 Jeff C0001 Harry
Advertisement
Answer
If I got it right
SELECT class_code, name1 FROM tbl WHERE class_code = class_code1 UNION --ALL SELECT class_code, name2 FROM tbl WHERE class_code = class_code2