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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:35:06+00:00 2026-05-17T20:35:06+00:00

Suppose: $sql = SELECT * FROM `artwork` WHERE approved = ‘1’ ; if($filter) $sql

  • 0

Suppose:

            $sql     = " SELECT * FROM `artwork` WHERE approved = '1' ";
if($filter) $sql    .= " AND $filter = '$filter_value' ";
            $sql    .= " ORDER BY subdate DESC, id DESC
                         LIMIT 30,30";

If I were to introduce a starting point (eg. WHERE id > 50) and that stipulation affected my LIMIT such that it only returned 10 results. I want 30 results, remember. Is there a way to start from record 1 and continue the selection?

edit: I realize I’m asking for id > 50 in this example and most certainly the first record if we were to rewind would have a lower ID. In my scenario that’s okay.

Thanks, Jason.

  • 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-17T20:35:07+00:00Added an answer on May 17, 2026 at 8:35 pm

    If there are 100 records and you’re
    only selecting 10 rows (#90 – #100),
    you want to get 20 more rows (#1 – #20)

    If those are your constraints, I don’t think you will be able to get the desired result set from a single query.

    Here’s a stored procedure which creates a temp table to get the desired result:

    DELIMITER //
    DROP PROCEDURE IF EXISTS TMP_TABLE_ARTWORK//
    CREATE PROCEDURE TMP_TABLE_ARTWORK (_offset INT, _count INT)
    BEGIN
    DECLARE res_total INT DEFAULT 0;
    SELECT COUNT(*) INTO res_total FROM artwork;
    CREATE TEMPORARY TABLE IF NOT EXISTS artwork_tmp ( t_pseudo INT, t_old INT, t_subdate DATETIME );
    INSERT INTO artwork_tmp ( t_pseudo, t_old, t_subdate ) SELECT artwork.id, artwork.id, artwork.subdate FROM artwork ORDER BY artwork.subdate DESC;
    INSERT INTO artwork_tmp ( t_pseudo, t_old, t_subdate ) SELECT ( artwork.id + res_total ), artwork.id, artwork.subdate FROM artwork ORDER BY artwork.subdate DESC;
    PREPARE STMT FROM "SELECT * FROM artwork_tmp ORDER BY t_pseudo LIMIT ?,?";
    SET @offset = _offset;
    SET @count = _count;
    EXECUTE STMT USING @offset, @count;
    DROP TABLE artwork_tmp;
    END //
    DELIMITER ;
    

    You’ll probably need to modify it to get it to do what you want (and apparently the prepared statement workaround is no longer required if you’re running a newer version of MySQL).

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

Sidebar

Related Questions

Suppose I have this query SELECT * FROM ( SELECT * FROM table_a WHERE
Suppose a query select * from employee returns 80 rows. I need to display
In SQL, using the table: mysql> select * from sentGifts; +--------+------------+--------+------+---------------------+--------+ | sentID |
Suppose we want to select the data from the database then we write the
I'm working on some SQL code. I'm familiar with the syntax SELECT * FROM
Suppose I have a string 'nvarchar(50)', which is for example the T-SQL string segment
I need to construct some rather simple SQL, I suppose, but as it's a
Suppose I have a PL/SQL stored procedure as follows: PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL)
INFORMIX-SQL or any other SQL-based DB: Suppose I have an app where depending on
I'd like to filter the results of a query which returns the results from

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.