EaBangalore EaBangalore - 1 month ago 6
MySQL Question

i have 3 tables in sql how to get data from last table

i have table relationship as shown in below pic

enter image description here

i have tables like this


  1. company



company_id + company_name



12 ibm

13 hp



  1. skills



skills_id + company_id



41 12

42 13



  1. skills_sets



id + skills_id + skills



1 41 php

2 42 java


my question is how to get php and java using join?

Answer

Try this:

SELECT ss.skills
FROM company c
LEFT JOIN skills s ON c.company_id = s.company_id
LEFT JOIN skills_sets ss ON s.skills_id = ss.skills_id

If You need to select exactly only "php" and "java" You need to add a "WHERE" condition:

SELECT ss.skills
FROM company c
LEFT JOIN skills s ON c.company_id = s.company_id
LEFT JOIN skills_sets ss ON s.skills_id = ss.skills_id
WHERE ss.skills IN ('php', 'java')

If some explanations needed check the documentation on sql alias and join.