-1

Tables 1 as below

User_Option_Experience


user_id | teaching_in 
        |  
111     |   1,2,3
112     |   1,4
113     |   4,2

Tables 2 as below

Teaching_in


IdTeaching | name
           |  
1          |   Biology
2          |   Chemistry
3          |   Mathematics

Now what i want is to have an output of all the names of subjects a User (Teacher) teaches in because one user as seen from the table can teach many subjects

For example I want all the subjects for user with id 111

I tried this but no success as it returns only one record

select teaching_in.name 
  from teaching_in 
  left 
  join users_options_experience 
    on user_options_experience.teaching_in = teaching_in.IdTeachingin 
 where user_options_experience.user_id = 15605
Strawberry
  • 32,714
  • 12
  • 37
  • 56

2 Answers2

0

SELECT a.user_id, GROUP_CONCAT(b.name ORDER BY b.IdTeaching) DepartmentName FROM User_Option_Experience a INNER JOIN Teaching_in b ON FIND_IN_SET(b.IdTeaching , a.teaching_in) > 0 GROUP BY a.user_id

Answered by enter link description here

user8286597
  • 141
  • 1
  • 2
0
SELECT  b.name 
FROM    User_Option_Experience a
        INNER JOIN Teaching_in b
            ON FIND_IN_SET(a.teaching_in , b.IdTeaching )
WHERE a.user_id=111;

Use FIND_IN_SET function of mysql

Hope this will help you.

Sumesh TG
  • 2,367
  • 1
  • 12
  • 29