sql - Similar queries to create third column in MySQL using JOIN -
using question, i've been trying experiment using different types of joins try combine these 2 select queries. similar , work fine when try create third column empfirstname3 query blows up. how combine these 2 tables?
htg_techprops table
empnumber | empfirstname 111 | bob 222 | john 333 | randy
htg_techstaffsets table
empnumber | staffsetid ccn31 | 111 ccn11 | 222 poww | null
/* techs */ select p.empnumber, p.empfirstname empfirstname1, t.empfirstname empfirstname2 htg_techprops p left join htg_techstaffsets s on p.empnumber=s.empnumber left join htg_techprops t on t.empnumber=s.staffsetid order p.empnumber /* staff sets */ select p.empnumber, p.empfirstname empfirstname1, t.empfirstname empfirstname2 htg_techprops p left join htg_techstaffsets s on p.empnumber=s.staffsetid left join htg_techprops t on t.empnumber=s.empnumber order p.empnumber
try this:
select p.empnumber, p.empfirstname empfirstname1, t.empfirstname empfirstname2 htg_techprops p left join htg_techstaffsets s on p.empnumber=s.empnumber left join htg_techprops t on t.empnumber=s.staffsetid union select p.empnumber, p.empfirstname empfirstname1, t.empfirstname empfirstname2 htg_techprops p left join htg_techstaffsets s on p.empnumber=s.staffsetid left join htg_techprops t on t.empnumber=s.empnumber order p.empnumber
Comments
Post a Comment