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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:41:03+00:00 2026-06-05T05:41:03+00:00

Basically what I’m trying to do is compare the IDs of rows against 15

  • 0

Basically what I’m trying to do is compare the IDs of rows against 15 results in MySQL, eliminating all but 1 (using NOT IN) and then pull that result.

Now normally this would be fine by itself, however the order of the 15 rows I’m doing the SQL query for are constantly changing based on a ranking, so there is a possibility that between the time the ranking updates, and the ajax request (which I submit the ID’s for NOT IN) more than just one ID has changed, which would of course bring back more than one row which I do not want.

So in short, is there a way in which I can query 15 rows, but only return one? Without having to run two separate queries.

Example

Say I have 7 items in my database, and I’m displaying 5 on the page to the user.

These are what are being displayed to the user:

Apple
Orange
Kiwi
Banana
Grape

But in the database I also have

Peach
Blackberry

Now what I want to do is if the user deletes an item from their list, it will add another item (based on a ranking they have)

Now the issue is, in order to know what they have on their list at the moment I send the remaining items to the database (say they deleted Kiwi, I would send Apple, Orange, Banana, and Grape)

So now I select the highest ranked 5 items from are remaining six items, make sure they are not the ones already displayed on the page, and then add the new one to list (either Peach or Blackberry)

All good and well, except that if both peach and blackberry now outrank grape, then I will be returning two results instead of just one. Because it would’ve queried…

Apple
Orange
Banana
Peach
Blackberry

and excluded…

Apple
Orange
Banana
Grape

Which leaves us with both Peach and Blackberry, instead of just Peach or Blackberry.

  • 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-05T05:41:04+00:00Added an answer on June 5, 2026 at 5:41 am

    I’m not sure I completely understood the requirements, but I’ll give it a try. The following example is based on my understanding, and it assumes you only want to display the top five rows.

    SELECT
      UL.ItemName
    FROM
      UserList UL
    WHERE
      (UL.Deleted = 0) -- Take only items that are NOT deleted
    
    UNION -- UNION clause discards duplicate entries, unlike UNION ALL
    
    SELECT
      I.ItemName
    FROM
      (SELECT
        IL.ItemName
      FROM
        ItemList IL -- This is the table containing ALL Items
      ORDER BY
        IL.Ranking ASC -- Most important Items first, supposing that a lower number in Ranking means higher priority
      ) AS I
    LIMIT 5 -- Display only top five entries
    

    Note: this query is untested, and there’s a good chance it won’t always return the items in the correct order, since it lacks an ORDER BY clause. Therefore, it should be taken as a suggestion and not as a complete solution.

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

Sidebar

Related Questions

Basically i'd like to allow an arbitrary (but not empty ) number of key-value
Basically I want to read and write to a file then save all the
Basically, I would like to decode a given HTML document, and replace all special
Basically, what I'm trying to create is a page of div tags, each has
Basically I'm attempting to add rows to a table, I need to do this
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically my sign up form is not working. When I sign someone up it
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.
Basically i'm trying to build a comment system. The user looks at a photo
Basically, what I am trying to do is to find last section of PE

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.