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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:02:23+00:00 2026-05-25T22:02:23+00:00

Can you suggest a query where a condition will be executed always . Say

  • 0

Can you suggest a query where a condition will be executed always . Say :

if($country == 'hong-kong')
{
    $cond = "AND country = 'china'";
}

    $q = "
            SELECT 
                    *
            FROM
                tbl_people
            WHERE
                region = 'asia'
                $cond
            ORDER BY RAND()
            LIMIT 0,15      
    ";

Now suppose $country = 'hong-kong' and it has total 4 members . What I want to know is is there any way so that if $country = 'hong-kong' I wll have 15 members in result set including the 4 members from hong-kong ?

  • 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-25T22:02:23+00:00Added an answer on May 25, 2026 at 10:02 pm

    If I understand the question correctly, you want 15 random results from a larger set, but you want to be sure that all of the results matching country = 'hong-kong' are included in those 15.

    I think you’re going to want two queries, because the number of records returned by the first one (country = 'hong-kong') will dictate the limit you put on the second query. E.g.:

    SELECT 
        *
    FROM
        tbl_people
    WHERE
        country = 'hong-kong'
    ORDER BY RAND()
    LIMIT 0,15      
    

    Then

    SELECT 
        *
    FROM
        tbl_people
    WHERE
        region = 'asia' AND country <> 'hong-kong'
    ORDER BY RAND()
    LIMIT 0,X
    

    …where X is 15 - N, where N is how many rows were returned by your first query.

    Then of course, you have to combine them in some kind of randomizing way (unless you want the Hong Kong results to be at the top/bottom/whatever of the list).

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

Sidebar

Related Questions

Can someone suggest me a good example or link to select records from MySQL
anyone can suggest me the query to delete multiple tables from database.?? like....... Drop
Wondering if anyone can suggest a good file replication tool that will replicate across
I'm wondering if people can suggest the best tutorial that will walk me through
Can someone suggest me how to build up the following query using JPA Criteria
Can anyone suggest an easy fix for the query below? Workout.all(:joins => [:person, :schedule],
how can i convert eps image to jpg/png. any good application you can suggest.
Can you suggest some good MVC framework for perl -- one I am aware
Can anyone suggest me a helpful programming language which can be used to create
Can somebody suggest a good free tool for analyzing .Net memory dumps other than

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.