title: C# get only top 10 highest selling items in database and put it to chart
body: <p>Hi everyone i already have a code to select products sales from a database and put it to chart, but its selecting all products. How can i get only 10? </p>
  
  <p>And what should be the query if need the opposite which the top 10 least selling products?</p>
  
  <p>Code: </p>
  
  <pre><code>  private void loadchart()
    {
      chart1.Series[0].Points.Clear();
      chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
      using (SqlConnection connection = new SqlConnection("Data Source=BENJOPC\\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True"))
      {
          SqlCommand command = new SqlCommand("Select ProductName, Sum(QtySold) as QtySold from Sales_productholder group by ProductName", connection);
  
          connection.Open();
  
          SqlDataReader read = command.ExecuteReader();
  
          while (read.Read())
          {
              this.chart1.Series["Pieces Sold"].Points.AddXY(read["ProductName"], read["QtySold"]);
  
          }
          read.Close();
      }
  }
  </code></pre>