Last post May 14, 2015 05:02 AM by Lokesh B R
May 14, 2015 02:39 AM|mubashirkhan|LINK
i have 2 tables :
i want to retrieve data so that the final table looks like this
but i hve no idea how to write the sql query .. any body knows how can i achieve that ...
or if i can re-design my tables so that retrieving is easy and efficient
May 14, 2015 03:19 AM|Lokesh B R|LINK
,(SELECT Name FROM [Subjects] where SubjectId = Sub1) AS Sub1
,(SELECT Name FROM [Subjects] where SubjectId = Sub2) AS Sub2
,(SELECT Name FROM [Subjects] where SubjectId = Sub3) AS Sub3
May 14, 2015 03:28 AM|asyed4u|LINK
from studenttable Stu
left join subjecttable subj1 on stu.sub1=subj1.subjectid
left join subjecttable subj2 on stu.sub2=subj2.subjectid
left join subjecttable subj3 on stu.sub3=subj3.subjectid
May 14, 2015 04:05 AM|mubashirkhan|LINK
thankx asyed4u.. it worked exactly as i wanted to ...
May 14, 2015 04:09 AM|Lokesh B R|LINK
did you check the query which i posted?
May 14, 2015 05:00 AM|mubashirkhan|LINK
i tried lokesh but i guess i need to know subject codes before hand to try ur query which is not possible .. also i doubt there are some performance issues as it is hitting the db 4 times for single operation... i may be wrong .. are their performance issues
with asyed4u's method ..
May 14, 2015 05:02 AM|Lokesh B R|LINK
1. You are not required to know the subject codes, that is a COLUMN Name.