Reputation: 11
I have three tables:
+------------------------------------------+
| profile_employee |
+------------------------------------------+
| id | first_name | last_name | phone | cv |
+----+------------+-----------+-------+----+
+------------+
| joburi |
+------------+
| id | titlu |
+----+-------+
+---------------------------------------+
| job_to_profile |
+---------------------------------------+
| id | id_job | id_profile | created_at |
+----+--------+------------+------------+
I want to select all of the information from all those three tables, I have this query but selects only first, last, phone, cv:
SELECT jtp.id,
jtp.created_at as data_aplicare,
profile_employee.first_name,
profile_employee.last_name,
profile_employee.phone,
profile_employee.cv
FROM profile_employee
LEFT JOIN job_to_profile jtp ON jtp.id_profile = profile_employee.id
If been through a load of answers here and still tearing my hair out to get the results I need. Can any SQL gurus out there see a simple solution. The potential JOINs required are frying my brain.
Upvotes: 1
Views: 82
Reputation: 544
Try to frame it like this:
Select *
from table A T1
inner join table B T2 ON t1.field = t2.field
inner join table C T3 on t1.field = t3.field
For example
SELECT * FROM profile_employee
LEFT JOIN job_to_profile jtp
ON profile_employee.id = jtp.id_profile
LEFT JOIN joburi juri
ON profile_employee.id = juri.id
Upvotes: 0
Reputation: 278
You start from the relation table job_to_profile and do an inner join to the two nomeclator tables profile_employee and joburi:
select
p.id, p.first_name, p.last_name, p.phone, p.cv
, j.id, j.titlu
, jp.id, jp.id_job, jp.id_profile, jp.created_at
from
job_to_profile jp
inner join joburi j on j.id = jp.id_job
inner join profile_employee p on p.id = jp.id_profile
Upvotes: 0
Reputation: 43574
You can use the following using a INNER JOIN
:
SELECT *
FROM profile_employee pe INNER JOIN job_to_profile jtp ON pe.id = jtp.id_profile
INNER JOIN joburi j ON jtp.id_job = j.id
Upvotes: 1