table_store
store_id title slug
1 Jabong jabong
2 Amazon amazon
table_coupon
coupon_id title store_id
1 Now 50% Off 1
2 New 2020 Sale 2
table_tag
tag_id title priority
1 Latest 5
2 Trending 4
3 Hot 3
table_tag_bind
id tag_id main_id(is coupon_id)
1 1 1
2 1 2
3 2 1
How can i list the products related to store based on tag priority. But dont repeat the same product if it has more than 1 tag. higher the number more tha priority:
my query: please what is wrong in this query?
SELECT DISTINCT(t1.`coupon_id`), t1.`title`
FROM `coupon` AS t1
LEFT JOIN `tag_bind` AS t2 ON t1.coupon_id = t2.main_id
LEFT JOIN `tag` AS t3 ON t3.id = t2.tag_id
WHERE t1.`store_id`='1'
ORDER BY t3.`priority` DESC