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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:52:45+00:00 2026-05-31T12:52:45+00:00

I am trying to do a mysql query to select some news stories from

  • 0

I am trying to do a mysql query to select some news stories from a table, now the key is I always need 5 results.

so I was hoping to be able to pad out my results with another where clause ie

select * from here where this = 1
if there is < 5 results then select * from here where this = 2
limit [how ever many we are short say the first query brings back 3 results this should bring back 2]

Now I’ve looked at using a union to do this but without outside help ie from php and another query to count the results I don’t think it is possible, I know I could simply use php to do this, and will probably end up doing that, but I was just wondering if what I am trying to do is possible with one mysql query?

EDIT:

also it needs to order by date but they are not really posted in order so

order by date get upto 5 where this = 1 and if there isn’t 5 pad it out with the remainder of where this = 2 also ordered by date.

Another Shameful Edit:

ask a silly question lol… it was my sleep deprivation I just assumed there was data in the table and the previous coder was using unions to do all sorts of stuff, making me think it was more complex than it should be

SELECT *
FROM
 news
WHERE
 ( this = 45 || this= 0 )
AND
 active =  '1'
ORDER BY
 this ASC,
 date_added DESC
LIMIT 5
  • 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-31T12:52:47+00:00Added an answer on May 31, 2026 at 12:52 pm

    How about –

    SELECT *
    FROM here
    WHERE this < 5 -- added this WHERE clause based on the idea that there will be at least one item per this
    ORDER BY this ASC, `date` ASC
    LIMIT 5;
    

    Or are you after the five results then being sorted by date again –

    SELECT *
    FROM (
        SELECT *
        FROM here
        WHERE this < 5 -- added this WHERE clause based on the idea that there will be at least one item per this
        ORDER BY this ASC, `date` ASC
        LIMIT 5
    ) AS tmp
    ORDER BY `date` ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a MySQL query. I'm trying to rank participants using
I trying to create a MySql Query from the $_POST values trouble is i
I'm trying to mesh the below mysql query results into a single json object,
I am trying to write a MySQL query that gives me results of Organisation
I have a mysql table containing news data and categories and i'm trying to
I'm trying to query my database to get some results in Chinese and Japanese
I'm trying to use ASIFormDataRequest for iphone to get some values from my mysql
I am trying to print a value retrieved from a MySQL query with javascript.
Ok, so I'm trying to make some simple code to display news articles from
I'm trying to insert some japanese words in a mysql table! If I insert

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.