MySql Query: Using Joins to get data not results good -


i have 2 tables: employeeinfo table (table 1) , itemsinfo table (table 2):

table 1:

enter image description here

table 2:

enter image description here

in ui screen , have 2 div layers - left div , right div. left div should load data of items not associated employee , right div should load data associated employee.

for example, on page load, employee empid=201, data in both div should populated this: enter image description here

to achieve this, want mysql query output this:

enter image description here

that returned json objects output :

[{"empid":"","itemid":"1","items":"apple"},{"empid":"201","itemid":"2","items":"banana"},{"empid":"","itemid":"3","items":"baseball"},{"empid":"","itemid":"4","items":"bikes"},{"empid":"201","itemid":"5","items":"blue"}] 

so can push data appropriate div getjson method. if empid=null, data pushed in left div else if empid=201, data pushed n right div.

i tried left join but, since in table 1, field values repeated more once, dont exact query output.

kindly me how achieve above scenario.. in advance.

your question bit hard read ui stuff you're throwing in. requested query output do:

select t1.empid, t2.itemid, t2.items    itemsinfo t2 left join employeeinfo t1 on t1.itemid=t2.itemid , empid=201; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -