有没有办法(使用一些mysql编程)避免在具有不同别名的同一个表上进行多个连接?例如,我有
SELECT *
FROM `container` AS `cont_link`
LEFT JOIN `custom_field_string` AS `sf0` ON cont_link.id = sf0.container_id AND sf0.custom_field_id=60
LEFT JOIN `custom_field_string` AS `sf3` ON cont_link.id = sf3.container_id AND sf3.custom_field_id=321
LEFT JOIN `custom_field_string` AS `sf4` ON cont_link.id = sf4.container_id AND sf4.custom_field_id=322
LEFT JOIN `custom_field_int` AS `sf1` ON cont_link.id = sf1.container_id AND sf1.custom_field_id=319
LEFT JOIN `custom_field_int` AS `sf2` ON cont_link.id = sf2.container_id AND sf2.custom_field_id=320
使用custom_field_string表连接3次,因为它具有不同的属性。我怎么能只用1个连接但保留不同的属性来做到这一点。 我有达到61连接限制的问题。
答案 0 :(得分:0)
SELECT *
来自container
AS cont_link
LEFT JOIN custom_field_string
AS sf0
ON cont_link.id = sf0.container_id AND sf0.custom_field_id in(60,321,322);
如果只有三行匹配,则此处将获得3个结果,而不是包含3列的1行。