我有一个这样的数据库结构:
SELECT * FROM Culture;
------------------------
Id ShortName FullName Supported
22 en-US English (United States) 1
23 fr-FR French (France) 1
24 hi-IN Hindi (India) 0
SELECT * FROM ResourceKey;
----------------------------
Id Name
20572 HowAreYou
20571 Hello
20573 ThisKeyHasUSEnglishValueOnly
SELECT * FROM Strings;
-----------------------
Id CultureId ResourceKeyId ResourceValue
41133 22 20571 Hello
41134 22 20572 How are you?
41135 23 20571 Bonjour
41136 23 20572 Comment allez-vous?
41137 22 20573 This key has US English value only.
SELECT * FROM Category;
------------------------
Id Name
1 JavaScript
SELECT * FROM StringCategory;
------------------------------
Id ResourceKeyId CategoryId
1 20571 1
2 20572 1
3 20573 1
我想显示所有资源键名称和资源值,即针对每个键的字符串值,例如法语(法国)文化,即具有ShortName
fr-FR的文化,但即使键在文化,它必须显示键名,但值为 NULL。像这样:
Name ResourceValue
-------------------------------------------------------
Hello Bonjour
HowAreYou Comment allez-vous?
ThisKeyHasUSEnglishValueOnly NULL
对我来说,这似乎是一个简单的 LEFT OUTER JOIN 应用程序,但我的代码不起作用。有人可以帮助纠正我的代码吗?
我的查询是:
SELECT ResourceKey.Name AS Name, ResourceValue
FROM
ResourceKey LEFT OUTER JOIN Strings
ON
Strings.ResourceKeyId = ResourceKey.Id
INNER JOIN StringCategory
ON
StringCategory.ResourceKeyId = Strings.ResourceKeyId
INNER JOIN Category
ON
StringCategory.CategoryId = Category.Id
LEFT OUTER JOIN Culture
ON
Strings.CultureId = Culture.Id AND Culture.Id = (SELECT Id FROM Culture WHERE ShortName = 'fr-FR')
AND
Category.Name = 'JavaScript';
不知何故,上述查询中的最后一个连接变成了一个内部连接,消除了那些在上述文化中没有价值的行。