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 8909969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:34:12+00:00 2026-06-15T03:34:12+00:00

I am trying to have a section in a shop I am creating to

  • 0

I am trying to have a section in a shop I am creating to display 5 random products, from that Category ID.

Firstly every category has an ID, and a set of Sub Catrgories, every Sub Cat has an ID, and within every Sub Cat is a number of products. Every Product also has an ID.

The Products table contains the ProductID and the SubCatID.
The SubCat Table Contains the SubCatID and The CatID
The Cat table contains only the CatID.

SO I need to display 5 random products by the CatID. I can get random products using a query similar to this:

$randomprod = mssql_query("SELECT TOP 5* FROM Products WHERE SubCatID = '1' ORDER BY NEWID()");
while ($echorand = mssql_fetch_array($randomprod)) { 

I need a way to join the tables so I can display all products under a certain CatID however, and am finding it difficult because my Products table doesn’t contain a CatID. I am aware there are a number of joins, but am fairly new to PHP and even newer to MS SQL. Can anyone tell me what join is best, or point me in the correct direction please?

  • 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-15T03:34:13+00:00Added an answer on June 15, 2026 at 3:34 am

    Join products to sub categories, join sub categories to categories, like this:

    SELECT TOP 5 Products.Name, SubCatergory.Name, Category.Name
    FROM Products
    INNER JOIN SubCatergory ON Products.SubCatID = SubCatergory.SubCatID
    INNER JOIN Catergory ON SubCatergory.CatID = Category.CatID
    WHERE Category.CatID = 1
    ORDER BY NEWID()
    

    I have used INNER JOIN in the above example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a header which has a fade left from light-blue
I have been trying to get this one section of my UI to immediatly
I have some XML which I'm trying to search: <debts> <section id=24 description=YYYYY> <section
I have trying to learn MVC4 Web API. I am running my project from
I am trying to have a method that takes in a username and will
I am trying to have an archive section in a template with a certain
I have a section of a view that I would like to submit to
I have been trying to set-up Maven for use in our dev department but
I'm using VBScript (ASP Classic) and SQL Server; I'm trying to have a section
I have this section of code that saves a list item on click to

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.