title: retrieve data from a database the most sold products by branch
body: <p>I'm trying to get the most sold product by Branch on my project but I didn't know what is the problem on my Sql query.</p>
  
  <p>Here is the schema of my database:</p>
  
  <p><a href="https://i.stack.imgur.com/omAGy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/omAGy.png" alt="enter image description here"></a></p>
  
  <p>The DIM_SOUS_CAT table is the product table and each product is categorized by Branch and Category</p>
  
  <p><strong>DIM_CAT data :</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/UkRxE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UkRxE.png" alt="enter image description here"></a></p>
  
  <p><strong>DIM_BRANCHE data</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8q8JH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8q8JH.png" alt="enter image description here"></a></p>
  
  <p><strong>DIM_SOUS_CAT data which is the product</strong></p>
  
  <p><a href="https://i.stack.imgur.com/0nuQT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0nuQT.png" alt="enter image description here"></a></p>
  
  <p>FAIT_VENTE data, which is the sales list</p>
  
  <p><a href="https://i.stack.imgur.com/fcfwk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fcfwk.png" alt="enter image description here"></a></p>
  
  <p>I  wrote a sql query but it doesn't work. here is the query:</p>
  
  <pre><code>select vf.id_branche, vf.id_categorie, count(*) 
  from vente_fact vf 
  GROUP by vf.id_branche, vf.id_categorie  
  HAVING count(*) = (  
     SELECT max(COUNT(*)) 
     FROM vente_fact vf2  
     GROUP by vf2.id_branche, vf2.id_categorie 
  ) 
  </code></pre>
  
  <p>any suggestions please !</p>