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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:26:37+00:00 2026-06-18T10:26:37+00:00

i have specific request related to slideshow on test page here: http://bybyweb.com/mealbook/ All the

  • 0

i have specific request related to slideshow on test page here:
http://bybyweb.com/mealbook/

All the big pictures should be an image from a random category, with three recipes from that category listed in text.
Small thumbnails should show random recipes from any category.

So, there should be 3 random categories, 12 recipes from these categories (grouped by 4), AND 9 random recipes, unrelated to the rest…

Database scheme:
category: id, title, parent_id
category_to_recipe: id, rec_id, cat_id (this table is there because recipe can be in more than one category)
recipes: id, name, etc, etc…

this query:

SELECT category_recipe.rec_id, category_recipe.cat_id, recipes.name, recipes.url, recipes.main_image, categories.id, categories.title
FROM recipes, category_recipe, categories
WHERE categories.id
IN ( 10, 30, 64 )
AND category_recipe.cat_id = categories.id
AND category_recipe.rec_id = recipes.id
ORDER BY RAND( )
LIMIT 12

returns 12 random recipes from 3 categories, but i need 4 recipes per category…
I guess that there are more possible solutions, and i will probably need nested selects, or something….

  • 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-18T10:26:38+00:00Added an answer on June 18, 2026 at 10:26 am

    I think you need union all for this:

    SELECT cr.rec_id, cr.cat_id, r.name, r.url, r.main_image, c.id, c.title
    
    from ((select cr.* from category_recipe where cat_id = 10 order by rand() limit 4
          ) union all
          (select cr.* from category_recipe where cat_id = 30 order by rand() limit 4
          ) union all
          (select cr.* from category_recipe where cat_id = 64 order by rand() limit 4
         ) cr join
         categories c
         on cr.cat_id = c.id join
         recipes r
         on cr.rec_id = r.id
    

    In addition, you should use ANSI standard join syntax. Your queries would also be more readable by using aliases.

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

Sidebar

Related Questions

This is a bit of a specific request unfortunately. I have a CMS that
I have a specific requirement that all children of a particular JComponent have double
I have searched through the related mod_rewrite qustions but I can't anything specific enough
In my rails 3.1 app, I have specific files that are to be loaded
I have a specific requirement to read a resource from jar file and then
I have a specific question about looping variable names in WPF. XAML code looks
I have a specific class C and I would like to overload some math
i have this specific question to do to you, i have a database from
I have a specific requirement of having a toggling table. By toggling I mean
I have a specific case in mind, but the question applies in general too.

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.