title: Multiple SELECT statements in JPA Repository with @Query
body: <p>I was trying to execute select statement with subnets, with <strong>@Query</strong> annotation with '<strong>nativeQuery = true</strong>' in repository.
  But it gives me the following error:</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException: ERROR: syntax error at or near "SELECT"</p>
  </blockquote>
  
  <p>The following is the query that gives me error</p>
  
  <pre><code>@Query(value="SELECT COUNT(cc.customer) AS tot FROM SELECT DISTINCT new RatingsAndReviews(c.customer,c.customerRating) FROM RatingsAndReviews AS c WHERE c.vehicle=?1 AS cc WHERE cc.customerRating=?2",nativeQuery = true)
      Integer getNoOfRatingsForStars(Vehicle vehicle,double starNumber);
  </code></pre>
  
  <p>The query is basically to select the ratings count for a particular starNumber out of 5 stars for a particular vehicle by customers.</p>
  
  <p>The sub SELECT query alone gives the expected results when executed as below</p>
  
  <pre><code>@Query("SELECT DISTINCT new RatingsAndReviews(c.customer,c.customerRating)  FROM RatingsAndReviews AS c WHERE c.vehicle=?1")
      List&lt;RatingsAndReviews&gt; getCustomersWhoRatedVehicle(Vehicle vehicle);
  </code></pre>
  
  <p>My result set for the above query is; An array of RatingsAndReviews objects</p>
  
  <pre><code>[
      {
          "customerRating": 2.0,
          "customer": {
              "customerId": 1,
              },
          },
      },
      {
          "customerRating": 3.0,
          "customer": {
              "customerId": 2,
              },
          },
      },
      {
          "customerRating": 2.0,
          "customer": {
              "customerId": 3,
              },
          },
      }
  ]
  </code></pre>
  
  <p>So what I want to get is the count of ratings from customers for particular no. of stars. For example,How many 3 stared ratings, 2 stared ratings... and so on.</p>
  
  <p>Query without setting 'nativeQuery = true' will Be:</p>
  
  <pre><code> @Query("SELECT COUNT(cc.customer) AS tot FROM (SELECT DISTINCT new RatingsAndReviews(c.customer,c.customerRating)  FROM RatingsAndReviews AS c WHERE c.vehicle=?1) AS cc WHERE cc.customerRating=?2")
      Integer getNoOfRatingsForStars(Vehicle vehicle,double star);
  </code></pre>
  
  <p>and this will give the following error</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.Integer</p>
  </blockquote>
  
  <p>please correct me if what I've done with the query is wrong and any sort help is appreciated.</p>