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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:15:30+00:00 2026-06-13T17:15:30+00:00

I have this table id fruit ——— 1 apple 2 banana <– 3 apple

  • 0

I have this table

id  fruit
---------
1   apple
2   banana <--
3   apple
4   apple
5   apple
6   apple
7   banana <----

8   apple
9   banana
10  apple

And I want to select rows until 2 bananas are found, like

SELECT id FROM table_fruit UNTIL number_of_bananas = 2

So the result would be 1,2,3,4,5,6,7

How could I achieve this?

thanks

I wish I could give credits to all of you who answered my question. I’v tested all of them, and they all work perfectly (got the expected result).

Though answers of Devart and ypercube seem a little bit complex and difficult for me to understand.

And since AnandPhadke was the first one provided a working solution, I’ll choose his answer as accepted.

You guys are awesome, thanks!

  • 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-13T17:15:31+00:00Added an answer on June 13, 2026 at 5:15 pm
    select * from tables where id <=
    
    (
    select id from (
    select id from tables where fruit='banana'
    order by id limit 2) a order by id desc limit 1
    )
    

    SQLFIDDLE DEMO

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

Sidebar

Related Questions

Lets say I have a plant table: id fruit 1 banana 2 apple 3
I have something like this: SELECT id, fruit, pip FROM plant WHERE COUNT(*) =
I have this PHP code of: $count = select count(fruit) as total, sum(fruit like
I have a file like this apple ae-pal noun. a fruit ball b'al noun.
I have this table And my goals is to have a table looking like
What is wrong with this piece of code? dic = { 'fruit': 'apple', 'place':'table'
I have in my rails form the following code: <label>Fruit: </label> <%= f.select(:IST_FRUIT, [['Apple',
Conceptually, I have a table with a list of fruit items. I want, in
I have a table like this table name: products +----+-------------+-----------+ | id | name
For a table (Ingredients) like this: +-----+-----+ |id |fruit| +-----+-----+ | 1 | or

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.