0

有树表:

电子邮件块

blocks_id  blocks_pos  url_type  blocks_folder  
1          1           1         emails_block   
2          2           1         emails_show    
3          3           1         emails_add     
4          4           0         emails_share   

Emails_blocks_text

texts_id  blocks_id  langs_code  
2         1          ru          
1         1          ua          
3         2          ua          

Emails_blocks_aliases

blocks_id  aliases_name  
1          news          
2          drafts        

并有查询:

SELECT `blocks_id`,  `blocks_folder`, `blocks_name`, `aliases_name`, `langs_code`
FROM `a_emails_blocks`
LEFT JOIN `a_emails_blocks_text` USING(`blocks_id`)
LEFT JOIN `a_emails_blocks_aliases` USING(`blocks_id`)
GROUP BY `blocks_id`
ORDER BY FIELD(`a_emails_blocks_text`.`langs_code`, 'ua', 'ru')

但是在结果上我有 blocks_id = 1而不是 langs_code 'ua',我有 langs 代码'ru'。 我不明白为什么不从另一张桌子订购。

blocks_id  blocks_folder  aliases_name  langs_code 

1          emails_block   news          ru          
2          emails_show    drafts        ua          
3          emails_add                               
4          emails_share                             
4

1 回答 1

0

您应该SELECT只使用您在GROUP BY或汇总结果中的字段

实际上在您的情况下您不需要GROUP BY,因为您没有任何聚合函数(sum、count、avg 等)

于 2013-06-12T09:14:57.710 回答