Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:45:15+00:00 2026-05-30T09:45:15+00:00

I have a query which I would like to tweak little bit to display

  • 0

I have a query which I would like to tweak little bit to display different info.
Currently my query gets all the orders with products ranked by the one with most conversions at the top.
Here is the query:

   SELECT nopv.ProductVariantID, COUNT(nopv.ProductVariantID), p.ProductId, c.CategoryID, c.Name FROM Nop_OrderProductVariant nopv
INNER JOIN Nop_ProductVariant npv
ON nopv.ProductVariantID = npv.ProductVariantId
INNER JOIN Nop_Product p
ON npv.ProductID = p.ProductId
INNER JOIN Nop_Product_Category_Mapping npcm
ON p.ProductId = npcm.ProductID
INNER JOIN Nop_Category c 
ON npcm.CategoryID = c.CategoryID
GROUP BY nopv.ProductVariantID, p.ProductId, c.CategoryID, c.Name
HAVING COUNT(*) > 0
ORDER BY COUNT(nopv.ProductVariantID) DESC

What I have as a result is:

enter image description here

I want to be able to have each category only one time, for example “programmers & modules” category should only one record, containing the sum of all the productvariantIDs in that category. The first field can be avoided as well, because if there are multiple productvariants, the query will need to show just one. What I really need is the count of each category and the categoryID.
Thanks in advance, Laziale

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:45:16+00:00Added an answer on May 30, 2026 at 9:45 am

    I think the issue is your group by:

    GROUP BY nopv.ProductVariantID, p.ProductId, c.CategoryID, c.Name
    

    Try:

    GROUP BY c.CategoryID, c.Name -- c.Name is here since you probably can't select it otherwise
    

    Then make whatever changes you need to your SELECT so it will work.

    So something like this:

    SELECT COUNT(nopv.ProductVariantID), c.CategoryID, c.Name
    FROM Nop_OrderProductVariant nopv
    INNER JOIN Nop_ProductVariant npv
    ON nopv.ProductVariantID = npv.ProductVariantId
    INNER JOIN Nop_Product p
    ON npv.ProductID = p.ProductId
    INNER JOIN Nop_Product_Category_Mapping npcm
    ON p.ProductId = npcm.ProductID
    INNER JOIN Nop_Category c 
    ON npcm.CategoryID = c.CategoryID
    GROUP BY c.CategoryID, c.Name
    HAVING COUNT(*) > 0
    ORDER BY COUNT(nopv.ProductVariantID) DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which gets all records ordered by last_name. Now I would
I have one query on which I would like to get your valuable feedback.
I have a query which produces a list of orders like this: Invoice Description
I have quite complicated query from which I would like to create a view.
I have 2 tables like which I would like to query to form a
I have three queries which I would like to consolidate into one query which
I have the following query in SQL which I would like to convert to
I have a query which is searching a database for orders. My SQL query
I would like to build the NSPredicate for a Core Data query which should
Anyone can help me, I am a bit stuck. I have this query which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.