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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:19:59+00:00 2026-06-06T21:19:59+00:00

I have this table services , with data as follows: service_id bepro_id service_name 1

  • 0

I have this table services, with data as follows:

service_id  bepro_id    service_name
        1   1   Virtuales
        2   2   Logos1
        3   3   Diseño C
        4   1   Formatos A3
        203 77  Dasdad
        6   2   Publi
        8   4   edificios Vi
        9   3   Maquillaje D
        10  7   Servicio 10 Serv
        11  4   servicio 11 tittle
        14  3   Lorem ipsum dol
        15  30  servicio 15 title
        16  4   Titulo TituloTitulo
        17  8   servicio 17 title ñ
        19  11  Retoques digital 
        20  4   servicio 20 title
        26  5   service 26 title
        27  7   servicio 27 tittle
        183 3   Excepteur sint occaecat 
        188 3    Duis aute irure dolor 
        185 3   Cillum dolore eu fugiat
        186 3   Eserunt mollit anim i
        190 3   Lorem ipsum dolor
        191 3   general para ed
        192 3   Ingenieria
        193 3   letras
        194 2   bocetos
        196 60  Retoque fotografico
        199 60  Maquetacion de 
        198 28  Revistas en General

I want to select from 8 distinct random values in bepro_id 1 to 8 per each values (minimun 1 ,maximun 8) each bepro_id.

I mean maximum 64 rows or minimum 8 rows. Then I have to JOIN with table “users” where services.bepro_id=users.users_id .

This selects only one random row per value ( I need min 1 max 8 values for each value) below @Andomar help me a lot but doesn’t seems to work and it look complicated for what it is , is that the only way i could do?:

SELECT * FROM  `services` GROUP BY bepro_id ORDER BY RAND( ) LIMIT 8

Thank you in advance

  • 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-06T21:20:01+00:00Added an answer on June 6, 2026 at 9:20 pm

    You could use the MySQL variable trick to label each row with a row number. An inner join can be used to limit the result to N bepro’s. The example below returns 1-2 random services for 3 random bepro’s. It should be easy to change those values.

    This is what i need thank to @Andomar :

    select  *
    from    (
            select  distinct bepro_id
            from    services
            order by
                    rand()
            limit   8 -- Eight random bepro_id's
            ) bepro
    join    (
            select  if(@last_bepro = bepro_id, @rn := @rn + 1, @rn := 1) as rn
            ,       (@last_bepro := bepro_id)
            ,       service_id
            ,       bepro_id
            ,       service_name
            from    services
            cross join
                    (select @rn := 0, @last_bepro := -1) r
            order by
                    bepro_id
            ) serv
    on      serv.bepro_id = bepro.bepro_id
    join    users 
    on      users.id = bepro.bepro.id
    where   serv.rn <= 8 -- 8 services max , 1 min per bepro_id
    order by
            rand();
    

    Live example at SQL Fiddle.

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

Sidebar

Related Questions

I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table [Table 1] cid | arrived | date_arrived The [arrived field
I have this table, which can be seen as a basic custom gantt chart:
I have this table And my goals is to have a table looking like
I have this table ---------------- | X | Y | ---------------- | a |
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
i have this table in UTF8 (collation is utf8_bin in case it matters). I

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.