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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:12:55+00:00 2026-05-25T12:12:55+00:00

I want to select some rows with a specific filter, but don’t limit if

  • 0

I want to select some rows with a specific filter, but don’t limit if I don’t get, at least, 40 rows.

It’s a pseudo-example:

SELECT * FROM `table`
WHERE
   SUM(1) < 40 OR
   `age` > 18

It’s similar to LIMIT, but LIMIT will consider the WHERE filter ever. I want to ignore the filter if I don’t have at least 40 rows (but accept the firsts rows).

How I do that?

Edit: a lot of people had doubts what I really wanted.

This is an example:

ID AGE
1  10
2  20
3  30
4  10
5  20
6  30
7  10

I want to get the first 2 rows EVER. And only after at least two rows, get new rows that match the given conditions (WHERE).

For example: I want the first 2 rows more rows whose age is 30. The result would be equivalent to:

ID AGE
1  10 <first>
2  20 <second>
3  30 <conditional>
6  30 <conditional>
  • 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-25T12:12:56+00:00Added an answer on May 25, 2026 at 12:12 pm

    You can use an increasing variable @rownum to simulate the same functionality. However, this is much less efficient than limit because the server brings the filtered-out rows into memory and continuously performs the @rownum:=@rownum+1 calculation.

    SELECT @rownum:=@rownum+1, t.*
    FROM `table` t, (SELECT @rownum:=0) r
    WHERE
       @rownum <= 40 OR
       `age` > 18
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select the most recent 12 rows from a table, but then
i want to select some rows from different tables and then i want to
I want to fetch some specific rows from MySQL database using multiple ids, for
I want to select some rows from a SQLite table, and add an empty
I have a table with 3 columns (A,B,C). I want to select some rows
I want to quickly select some rows, format it nicely for a dropdownlist/selectlist or
I have some code that grabs some rows from a table and I want
I want to select some rows and immediately update a process column in that
I have a grouped UITableView and want to select some rows. Hers some handy
I want to add some rows to a database using Linq to SQL, but

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.