SELECT
description
FROM
diagnosis_mapping
LEFT JOIN
diagnosis_codes
ON
diagnosis_codes.codeid = diagnosis_mapping.codeid
SELECT
description
FROM
diagnosis_mapping
LEFT JOIN
diagnosis_codes
ON
diagnosis_codes.codeid = diagnosis_mapping.secondarycodeid
How to merge these 2 queries and get info in a single resultset?
In first i need to match with codeid and in second i need to match with secondarycodeid to the same mastertable to fetch the description of both.
You can do two joins in one query, just give an alias to the table names so MySQL knows what you want to get:
In this example,
ais an alias for the firstdiagnosis_codestable andbto the other. When you give alias names to the tables, MySQL (and any other SQL aware database) treats them basically as two separate tables and fetches data from them independently.