这是我的查询:
SELECT companies.id, companies.business_number, companies.country_iso_3, companies.profile_img, companies.short_url, companies_details_en.company_name
FROM companies
JOIN companies_details_en ON companies_details_en.company_id = companies.id
LEFT JOIN companies_main_activity_tags ON companies_main_activity_tags.company_id = companies_details_en.company_id
WHERE (
companies.id = '1'
OR companies.id = '3'
OR companies.id = '4'
OR companies.id = '5'
OR companies.id = '7'
OR companies.id = '20'
OR companies.id = '21'
OR companies.id = '22'
)
AND ((companies_main_activity_tags.val LIKE '%xxxx%') OR (companies_main_activity_tags.val LIKE '%yyyy%') OR companies_main_activity_tags.lang = 'en')
AND companies.id = companies_details_en.company_id
AND companies.id = companies_main_activity_tags.company_id
LIMIT 0 , 30
我想获取所有具有我想要的 id 的公司(ids 列表)以及在表中具有输入标签“yyyy”或“xxxxx”之一的公司companies_main_activity_tags.val
作为他们的主要活动。但我的查询返回一些结果两次甚至更多(取决于他们拥有的标签数量)
我该如何解决这个问题?
谢谢