mike182uk
11-05-2009, 10:37 PM
Hi there, i am doing an innerjoin on some tables. basically i have 1 main table that i am retrieveing data from. The columns in the table reference the id's of another table. multiple columns in the db referenece different id's in the second table. now to achieve getting the results i want i am finding myself doing 3 inner joins on the same table. is there an easier to do this? here is the sql i am using:
SELECT
locationcounty.Description AS location,
pv1.Description AS industry,
pv2.Description AS type,
pv3.Description AS salaryfrequency,
vacancies.JobTitle,
vacancies.Deadline,
vacancies.LocationTown,
vacancies.JobDescription,
vacancies.SalaryText
FROM
vacancies <--MAIN DB
Inner Join vacancies_location_counties ON vacancies.ID = vacancies_location_counties.VacancyID
Inner Join locationcounty ON vacancies_location_counties.LocationCountyID = locationcounty.ID
Inner Join picklist_values AS pv1 ON vacancies.JobBoardCategoryID = pv1.ID
Inner Join picklist_values AS pv2 ON vacancies.JobTypeID = pv2.ID
Inner Join picklist_values AS pv3 ON vacancies.SalaryFrequencyID = pv3.ID
WHERE
vacancies.ID = '37'"
so the picklist_values contains multiple values that i need. and ther all unique id's. This is a rubbish db design but the client insists i use it and i cannot alter any part of the db.
from the sql above im getting the results i need, it just seems a little long winded and i wondered if ther was a better way? (except redesigning the db)
SELECT
locationcounty.Description AS location,
pv1.Description AS industry,
pv2.Description AS type,
pv3.Description AS salaryfrequency,
vacancies.JobTitle,
vacancies.Deadline,
vacancies.LocationTown,
vacancies.JobDescription,
vacancies.SalaryText
FROM
vacancies <--MAIN DB
Inner Join vacancies_location_counties ON vacancies.ID = vacancies_location_counties.VacancyID
Inner Join locationcounty ON vacancies_location_counties.LocationCountyID = locationcounty.ID
Inner Join picklist_values AS pv1 ON vacancies.JobBoardCategoryID = pv1.ID
Inner Join picklist_values AS pv2 ON vacancies.JobTypeID = pv2.ID
Inner Join picklist_values AS pv3 ON vacancies.SalaryFrequencyID = pv3.ID
WHERE
vacancies.ID = '37'"
so the picklist_values contains multiple values that i need. and ther all unique id's. This is a rubbish db design but the client insists i use it and i cannot alter any part of the db.
from the sql above im getting the results i need, it just seems a little long winded and i wondered if ther was a better way? (except redesigning the db)