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

  • Home
  • SEARCH
  • 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 7781751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:19:41+00:00 2026-06-01T19:19:41+00:00

My first post here. I am trying to sort values displayed from my products

  • 0

My first post here.

I am trying to sort values displayed from my products table with values inside my products_categories table.

my products table contains the following fields:

id | psku | pname | pdescription

My products_categories table has the following fields:

id | psku | subcategory | orderid

The site I am building is a small eshop, which contains several subcategories. The setup at this time allows me to have 1 product added to multiple categories.

For example, product sku# 6001 would be listed in 2 subcategories, cosmetics & eyelashes. I would have then 2 entries in my products_subcategories table like so:

id | psku | subcategory | orderid
1 | 6001 | cosmetics | 1
2 | 6004 | eyelashes | 1
3 | 6003 | cosmetics | 2
4 | 6011 | cosmetics | 3
5 | 6020 | eyelashes | 2
6 | 6045 | cosmetics | 4

I am currently using the following query to display data in each subcategory:

SELECT * FROM products LEFT JOIN products_subcategories 
ON products.psku = products_subcategories.psku 
WHERE products.psku IN ('6001','6003','6011','6020','6045') 
GROUP BY e2o_products_subcategories.psku 
ORDER BY e2o_products_subcategories.orderid ASC

This should display my result as so:

Cosmetics:
PSKU 6001
PSKU 6003
PSKU 6011
PSKU 6045

eyelashes:
PSKU 6004
PSKU 6020

It doesn’t seem to work. Tried some other combinations, with worst result. The products show, but will not sort by orderid

Would someone have a possible solution to this problem. I can provide sample data if needed.

Thank you.

  • 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-06-01T19:19:43+00:00Added an answer on June 1, 2026 at 7:19 pm

    I have had a look at the sampledata.php file that you have created. I am struggling to make sense of what you are trying to do. Why are you running two queries? Surely you could achieve the same result with a single query.

    Your first query will return a list of pskus that you are then passing into the second query –

    SELECT psku, subcategory
    FROM products_subcategories
    WHERE subcategory = 'cosmetics'
    
    +------+-------------+
    | psku | subcategory |
    +------+-------------+
    | 6018 |  cosmetics  |
    | 6017 |  cosmetics  |
    | 6022 |  cosmetics  |
    | 6025 |  cosmetics  |
    +------+-------------+
    

    The second query is then –

    SELECT DISTINCT products.*
    FROM e2o_products
    INNER JOIN e2o_products_subcategories 
        ON e2o_products.psku = e2o_products_subcategories.psku 
    WHERE e2o_products.pstatus =  '1' 
    AND e2o_products.psku IN (6018,6017,6022,6025)
    GROUP BY e2o_products.psku
    ORDER BY e2o_products_subcategories.dsporder DESC
    

    Given that you are only retrieving the fields from the products table you can just do –

    SELECT p.*
    FROM products p
    INNER JOIN products_subcategories ps
        ON p.psku = ps.psku 
    WHERE p.pstatus = 1
    AND ps.subcategory = '$subcat'
    ORDER BY ps.dsporder DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post ever here I'm trying to replicate this sort of JSON object so
first post here, and probably an easy one. I've got the code from Processing's
This is my first post here and I wanted to get some input from
this is my first post here! I'm trying to make a windows forms program
This is my first post here after many visits. Hello! I am trying to
that is my first post I am trying here, to get the names of
First post here so sorry if I seem like a newb, I am trying
I'm trying to set up Jekyll so that a quote from the first post
this is my first post here , I am trying to achive something in
newbie here, first post. I just spent like 4 hours trying to assign one

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.