這裏是我的查詢:重複結果加入
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
我想所有我想要的IDS(入侵檢測系統列表)的公司,並與它們具有輸入的標籤「YYYY」的企業之一或表companies_main_activity_tags.val
中的'xxxxx'作爲他們的主要活動。但我的查詢返回一些結果兩次或更多(取決於他們有多少標籤)
我該如何解決這個問題?
感謝
你忘了啓動支架「(」爲OR條件,以及您忘記關閉支架和狀況。我有更新查詢我的回答嘗試,這將解決您的問題。 –