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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:17:10+00:00 2026-05-16T00:17:10+00:00

I have a product table like this: Product name , Affiliate ID , ProductCode

  • 0

I have a product table like this:

Product name , Affiliate ID , ProductCode
a, 1, 1
b, 1, 2
c, 1, 3
d, 1, 5
e, 1, 7
f, 2, 4
g, 2, 6

I want to return first four products from each Affiliate ID. The ‘ProductCode’ column signifies the order in which the products were added, so can I use this column to sort my results. But I don’t know how to return the first four results from each Affiliate ID? If I use the ‘group’ function it returns only one row of each affiliate ID.

  • 1 1 Answer
  • 2 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-16T00:17:11+00:00Added an answer on May 16, 2026 at 12:17 am

    Look to the example in this link:

    Within-group quotas (Top N per group)

    it is exactly that you need.

     SELECT AffiliateId, ProductCode 
     FROM ( 
        SELECT 
          AffiliateId, ProductCode, 
          IF( @prev <> ID  @rownum := 1, @rownum := @rownum+1 ) AS rank, 
          @prev := ID 
        FROM your table 
     JOIN (SELECT @rownum := NULL, @prev := 0) AS r 
     ORDER BY AffiliateId, ProductCode 
     ) AS tmp 
     WHERE tmp.rank <= 4
     ORDER BY AffiliateId, ProductCode; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have a SQL lookup table like this: CREATE TABLE Product(Id INT IDENTITY PRIMARY
I have two tables like this Table Product ProductId - int <PK> ProductExpiry -
I have 2 tables which in simplified form look like this: Products( id: int,
I have two tables: **Product** ID Name SKU **Brand** ID Name Product table has
I have two tables as follows PRODUCT table Id | Name | Price And
Which is your preference? Let's say we have a generic Product table that has
I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for
I have a Table called Product and I have the Table StorageHistory . Now,

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.