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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:31:57+00:00 2026-05-16T14:31:57+00:00

SELECT student_id FROM `students` AS s1 WHERE student_id IN (SELECT s2.student_id FROM `students` AS

  • 0
SELECT student_id FROM `students` AS s1
WHERE student_id IN 
  (SELECT s2.student_id FROM `students` AS s2
     WHERE s1.year_of_birth = s2.year_of_birth
     LIMIT 10)

Can’t process this query on my server. It drops errors, that says that this version of mysql doesn’t support limit inside subqueries etc(ERROR 1235).

Is there any solution for my version of mysql 5.1.49?

SELECT
    id,
    region
FROM (
    SELECT
        region,
        id,
        @rn := CASE WHEN @prev_region = region
                    THEN @rn + 1
                    ELSE 1
               END AS rn,
        @prev_region := region
    FROM (SELECT @prev_region := NULL) vars, ads T1
    ORDER BY region, id DESC
) T2
WHERE rn <= 4
ORDER BY region, id

Thanks to Mark Byers

  • 1 1 Answer
  • 2 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-16T14:31:57+00:00Added an answer on May 16, 2026 at 2:31 pm

    I think you want any ten students with each birthdate. This is a greatest-n-per-group query and you can search Stack Overflow to see how this can be done in MySQL.

    It would be easy if MySQL supported the ROW_NUMBER function, but since it does not you can emulate it using variables. For example to get 3 students for each birth date you could do it like this:

    SELECT
        student_id,
        year_of_birth
    FROM (
        SELECT
            year_of_birth,
            student_id,
            @rn := CASE WHEN @prev_year_of_birth = year_of_birth
                        THEN @rn + 1
                        ELSE 1
                   END AS rn,
            @prev_year_of_birth := year_of_birth
        FROM (SELECT @prev_year_of_birth := NULL) vars, students T1
        ORDER BY year_of_birth, student_id DESC
    ) T2
    WHERE rn <= 3
    ORDER BY year_of_birth, student_id
    

    Result:

    1, 1990
    2, 1990
    5, 1990
    4, 1991
    7, 1991
    8, 1991
    6, 1992
    

    Test data:

    CREATE TABLE students (student_id INT NOT NULL, year_of_birth INT NOT NULL);
    INSERT INTO students (student_id, year_of_birth) VALUES
    (1, 1990),
    (2, 1990),
    (3, 1991),
    (4, 1991),
    (5, 1990),
    (6, 1992),
    (7, 1991),
    (8, 1991);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what would be the result of following query? select StudentName from Students where StudentName
Possible Duplicate: java PreparedStatement Can I make the prepared statement SELECT * FROM STUDENTS
When you use mysql, you can do something like this: SELECT * FROM student
How do I get to make this sqsl query work: SELECT student.LASTNAME, student.FIRSTNAME, student.IDNO,
I am trying to run a query that selects values from a table using
I have the following MySQL query: SELECT s.student_id, s.student_firstname, s.student_lastname, s.isActive, c.city_name, sd.student_startdate, sd.student_enddate,
The sql syntax is following: SELECT y.NAME, y.EMAIL, k.DATE, k.WORK_NR, k.SCORE, k.FILENAME FROM bas1.students
my query is select m.year_id,Count(*) as Distinctions from NewTestDB.dbo.[Master_MARKS2005] as m join NewTestDB.dbo.Master_Student as
The SQL would be something like select GeneralData.id, GeneralData.name, GeneralData.last_name, Student.id from GeneralData Inner
I have the following query SELECT s.name, s.surname, s.id_nr, s.student_nr, s.createdate, s.enddate, (SELECT count(*)

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.