mysql - ORDER BY based on maximum number of row appearence -


table fields: shop_id , product_id

  1. i want list of shops having specific products(should have @ least 1 product)
  2. results should sorted on basis of shops having maximum number of specified products

i write sql query 1st part, list not sorted according shops match maximum number of products

select      shop_id,     product_id     products_table     product_id in (1,2,3) order ??? 

is there optimal solution?

join subquery gets counts each shop, , order that.

select a.shop_id, a.product_id products_table join (select shop_id, count(*) product_count       products_table       product_id in (1, 2, 3)       group shop_id) b on a.shop_id = b.shop_id product_id in (1, 2, 3) order b.product_count desc 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -