Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY help (might get long)

Status
Not open for further replies.
Feb 14, 2002
88
JP
I don't think a JOIN is the answer here. I'm moderate at best at MySQL.

Anyways, I've got two tables. An info table and a description table. The two tables share an ID column. The info table has no null values. The description table will have at least one description to correspond to an item in the info table... sometimes more. If there's only one description, it will be in English. If it has more, there's a chance it's in Japanese (denoted by a column).

My query is fine and dandy for English, but it doesn't work for Japanese. As before, there isn't always a Japanese description. If there's not, my last conditional will always fail (as you shall see). Here's the query when want to display a Japanese description:

Code:
SELECT title,developer,publisher,
IFNULL(gm_dsc.description, ' ') as description
FROM info
LEFT JOIN dsc ON info.id = dsc.id
WHERE dsc.language = "j"
AND gm_info.id = "100"

I realize the problem is that if there's no Japnese description, WHERE dsc.langauge = "j" won't be true, and won't get the row... just not sure how I'd get around this (other than creating a seperate table for Japanese descriptions or doing some kung fu w/ PHP).

Thanks
 
Code:
SELECT title,developer,publisher,
coalesce(dsc.description, ' ') as description
FROM info
LEFT JOIN dsc ON info.id = dsc.id
and dsc.language = 'j'
where info.id = 100

Why gm_ in some places?
 
Why gm_ in some places?

Oops. Mistake. :) Those are the real names of the tables, but just (attempted) to truncate them here to make it easier on the eyes.

Code:
SELECT title,developer,publisher,
IFNULL(dsc.description, ' ') as description
FROM info
LEFT JOIN dsc ON info.id = dsc.id
WHERE dsc.language = "j"
AND info.id = "100"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top