如何选择即10篇文章而不必运行1次查询来获取每篇文章翻译(共11个查询)?我有3张桌子;文化,文章和翻译:选择多个翻译后的文章(记录)
Cultures
id code language
-- ---- ---------
1 en English
2 no Norwegian
Articles
id title content
-- ----- -------------
1 Home Hello, world!
2 About This is me...
...
Translations
id culture object FK field value
-- ------- ------ -- ------- ---------------
1 1 Page 1 title Home
2 1 Page 1 content Hello, world!
3 2 Page 1 title Hjem
4 2 Page 1 content Hei, verden!
5 1 Page 2 title About
6 1 Page 2 content This is me...
7 2 Page 2 title Om
8 2 Page 2 content Dette er meg...
...
任何帮助将不胜感激!
编辑:说我想取所有的文章,翻译成挪威文。这是我的不完整的查询(它尚未连接到FK A.ID):
SELECT
a.id,
(SELECT tr.value FROM translations tr WHERE tr.object='Page'
AND field='title' AND tr.culture=2) as title,
(SELECT tr.value FROM translations tr WHERE tr.object='Page'
AND tr.field='content' AND tr.culture=2) as content
FROM
articles a
编辑2:同样的问题,因为这: Best mysql query for selecting multiple rows that EACH need multiple associative rows from another table
这是功课? – Konerak 2011-06-06 07:19:04
如果您只能抓取文章,您为什么要抓取翻译? – piotrm 2011-06-06 07:21:00
@Konerak不,我迷路了,在一个客户项目上工作,没有超级经验,寻求帮助。 – asdf 2011-06-06 07:23:20