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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:14:00+00:00 2026-06-10T08:14:00+00:00

Possible Duplicate: How to select all records from table apart from the last 100

  • 0

Possible Duplicate:
How to select all records from table apart from the last 100

I wish to run a cron job wiping out some customer information. I have a table which stores the customers information and I am just testing SQL queries to make sure it will work. I am having problems with this:

$result = mysql_query("SELECT * from order-table WHERE order_id NOT IN (
SELECT order_id
from order-table
ORDER BY order_id desc) LIMIT 50");


while($row = mysql_fetch_array($result)){

echo $row['order_id'];

echo "<br />";
}

The problem is that I receive an error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

If I try the query directly in SQL I get a message that LIMIT is not supported in a subquery, so I was hoping someone might be able to help me achieve this in another way? Thank you for your time.

  • 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-10T08:14:02+00:00Added an answer on June 10, 2026 at 8:14 am

    You can’t have LIMIT inside an IN or NOT IN subquery. But you can in a subquery in the FROM or WHERE clause. The trick is to have the subquery return 1 row only and then use < or <= to compare that value.

    This will show all rows except the (ordered by order_id) last 50:

    SELECT ot.* 
    FROM order-table AS ot 
      JOIN 
        ( SELECT order_id
          FROM order-table
          ORDER BY order_id DESC
            LIMIT 1 OFFSET 50
        ) AS lim
        ON ot.order_id <= lim.order_id ; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Writing an SQL query to SELECT item from the following table I
Possible Duplicate: jquery: select the last 4 items in the list jQuery has the
Possible Duplicate: How do I randomly select an item from a list using Python?
Possible Duplicate: Retrieving the last record in each group Hi all i am having
Possible Duplicate: How disable Copy, Cut, Select, Select All in UITextView I have some
Possible Duplicate: transfer data from javascript popup multiline textbox to a select control I
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: Use LINQ to read all nodes from XML I am trying to
Possible Duplicate: jQuery disable SELECT options based on Radio selected (Need support for all
Possible Duplicate: Mysql single query join 3 table and get all the results Hi

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.