sql - Select QUERY inner joining Fields to get text values instead of ID's -
i have table looks this...
tbl1 user originalvalue newvalue fieldname mikes 11 12 dept bobl 140 141 position johns 11 south st 13 south st address jenb 9 12 amountpaid billys 133 132 seller here's table looks like. in case user edited record, saved original values , new values. here's i'm trying do. need able display text instead of id's (numbers). exception of (in example) amountpaid, , address - values in tbldefinition looks this.....
tbldefinition id name field 9 somevalue somex 10 somevalue somex 11 accounting dept 12 finance dept 132 microsoft seller 133 apple seller 140 manager position 141 entry position so wanted include bunch of data illustrate tbldefinition looks like. i'm trying somehow able use field , id tbl1 , join tbldefinition text values. need use fieldname because of values might appear in original , new values such fieldname = amountpaid have corresponding values in tbldefinition, need display value - in case 9, , 12.
select originalvalue, newvalue, field tbldefinitions left join tbldefinitions on (tbl2.originalvalue = tbldefinitions.id , tbl2.newvalue=tbldefinitions.id) here's i've been trying not going anywhere - i'm having hard time figuring out if can in 1 query, or if need multiple unions each field has corresponding text value in tbldefinitions or what
edit. maybe like....
select t2.name originalvalue tbl1 t1 inner join tbldefinitions t2 on t2.id = t1.originalvalue field in ('dept', 'position', 'seller') maybe long specify fields for, won't effect other values such amount paid in tbl1
if understanding correctly, should join definition table twice, once original name , once new name.
select tbl2.originalvalue ,tdo.name originalname ,tbl2.newvalue ,tdn.name newname ,tbl2.user tblbhh_hxfieldchanges tbl2 left join tbldefinitions tdo on tbl2.originalvalue = tdo.id left join tbldefinitions tdn on tbl2.newvalue = tdn.id
Comments
Post a Comment