I have a query that does a simple LEFT JOIN to determine whether there's a match in a second table. My problem is that the comparing column on the left side might be different depending on the data in another column.
Here's the skinny: the data are being loaded from a file list on our server. The unique identifier I'm using in my query on the left side might be in column 'level_06' or 'level_07' depending on whether it's category is flagged 'Feature' or 'Department' in the column 'level_05'.
If it's 'Feature', then the FROM clause needs to focus on 'level_06'. If it's a Department, then it need to focus on 'level_07'.
I'm not sure how to construct a query for this, but I used a query I found on MySQL's reference manual and tried to adjust it based on how I know an IF statement works. But it doesn't work here. Any clues on how to rewrite this?
Thx.
Here's the skinny: the data are being loaded from a file list on our server. The unique identifier I'm using in my query on the left side might be in column 'level_06' or 'level_07' depending on whether it's category is flagged 'Feature' or 'Department' in the column 'level_05'.
If it's 'Feature', then the FROM clause needs to focus on 'level_06'. If it's a Department, then it need to focus on 'level_07'.
I'm not sure how to construct a query for this, but I used a query I found on MySQL's reference manual and tried to adjust it based on how I know an IF statement works. But it doesn't work here. Any clues on how to rewrite this?
Code:
SELECT newline.*, magstat_data.story_slug
IF(
newline.level_05='Feature',
FROM newline LEFT JOIN magstat_data ON newline.level_06 = magstat_data.story_slug,
FROM newline LEFT JOIN magstat_data ON newline.level_07 = magstat_data.story_slug
)
WHERE magstat_data.story_slug IS NULL;
Thx.