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

The Archive Base Latest Questions

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

I’m trying to display a list of shops each with 3 random items from

  • 0

I’m trying to display a list of shops each with 3 random items from their shop, if they have 3 or more listings, that are actively advertising. I have 3 tables: one for the shops – “Shops”, one for the listings – “Listings” and one that tracks active advertisers – “AdShops”.

Using the below statement, the listings returned are random however I’m not getting exactly 3 listings (rows) returned per shop.

SELECT AdShops.ID, Shops.url, Shops.image_url, Shops.user_name AS shop_name,
       Shops.title, L.listing_id AS listing_id, L.title AS listing_title,
       L.price as price, L.image_url AS listing_image_url, L.url AS listing_url
FROM   AdShops INNER JOIN
       Shops ON AdShops.user_id = Shops.user_id INNER JOIN
       Listings AS L ON Shops.user_id = L.user_id
WHERE  (Shops.is_vacation = 0 AND Shops.listing_count > 2 AND 
        L.listing_id IN
            (SELECT TOP 3 L2.listing_id
             FROM   Listings AS L2
             WHERE  L2.listing_id IN 
                 (SELECT TOP 100 PERCENT L3.listing_id
                  FROM   Listings AS L3
                  WHERE  (L3.user_id = L.user_id)
                 )
             ORDER BY NEWID()
            )
       )
ORDER BY Shops.shop_name

I’m stumped. Anyone have any ideas on how to fix it?

The ideal solution would be one record per store with the 3 listings (and associated data) were in columns and not rows – is this possible?

  • 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-14T14:10:17+00:00Added an answer on May 14, 2026 at 2:10 pm

    If I’m not mistaken, below query should give you every user_id having at least 3 random listing_id’s.

    SELECT  user_id
            , listing_id
    FROM    (
              SELECT  l.user_id 
                      , l.listing_id
                      , RowNumber = ROW_NUMBER() OVER (PARTITION BY l.user_id ORDER BY NEWID())
              FROM    Listings l
                      INNER JOIN (
                        SELECT  user_id
                        FROM    Listings
                        GROUP BY
                                user_id
                        HAVING  COUNT(*) >= 3
                      ) cnt ON cnt.user_id = l.user_id  
            ) l 
    WHERE   l.RowNumber <= 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a list of all files found in the selected
When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a
I'm trying to display a series of titles varying from 60 characters to 160
I am trying to display a pie chart that shows sales by company. However
I have a long scrolling list of EditText items created by a SimpleCursorAdapter and
I have a RadComboBox that I am using to display department name and abbreviations.
I've been trying to display text using a Quartz context, but no matter what
I'm trying to display a loading icon while my iPhone app downloads a network
I'm trying to display an array of files in order of date (last modified).
I'm trying to display a caret ( ^ ) in math mode in LaTeX

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.