I'm learning some more SQL, and ran into a "problem",
I have two tabels like the link below
http://www.sqlfiddle.com/#!2/403d4/1
EDIT:
Since I'm quite retarded now from all SQL-test i have done this weekend, i asked really wrong...
Sorry guys...
What i really wanted:
If i have the requested language, i want to get all the records, and if the requested language is not in the titles-table, i want it to say "" or null...
like if i ask for all records in 'de', i want:
1 | ACHTUNG
2 | NULL
and if i ask for all the records in 'en' i want
1 | WARNING
2 | Ambulance
Really sorry for the wrong question.
/*
What i want to do:
I have the ID of a record and the requested language.
If the selected language does not exsists, i want it to take the other language.
like if i have:
language = 'de' and id = 1
I want 'ACHTUNG',
if i have:
language = 'de' and id = 2
i want "Ambulance" since there's no 'de'...
*/
How do i do this?
解决方案SELECT rec.id, title.name
FROM Records rec
LEFT JOIN Titles title ON title.record_id = rec.id and title.language='de';
SELECT rec.id, title.name
FROM Records rec
LEFT JOIN Titles title ON title.record_id = rec.id and title.language='en';
ID NAME
1 ACHTUNG
2 (null)
ID NAME
1 Warning
2 Ambulance