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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:48:51+00:00 2026-05-16T07:48:51+00:00

How to return a select result with batches through a single query, that should

  • 0

How to return a select result with batches through a single query, that should be a straight forward compound select somehow. Below is a sample table and a simple query that will generate the desired result by currently using a temporary numeric column that could not work in the final real world process.

There are only two key columns involved: ip addresses and oid addresses for various SNMP items at that address. Need to have the returned results in groups of up to 10 items per ip address and then going to the next IP address and return up to 10 more and so on and when one pass through all the IP addresses is complete go back to the first IP and return the second group of up to 10, next IP and 10 and so on.

Here is some sample data and simple query that somehow needs to be a compound query

— Table structure for table test

CREATE TABLE `test` (
 `ip` varchar(16) collate latin1_general_ci NOT NULL,
 `oid` varchar(50) collate latin1_general_ci NOT NULL,
 `element` varchar(16) collate latin1_general_ci NOT NULL,
 `temp` tinyint(4) NOT NULL,
 PRIMARY KEY  (`ip`,`oid`),
 KEY `element` (`element`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

—

— Dumping data for table test

INSERT INTO `test` VALUES 
   ('1', '1.1.1', 'a', 1),
   ('1', '1.1.2', 'b', 1),
   ('1', '1.1.3', 'c', 1),
   ('1', '1.1.4', 'd', 1),
   ('1', '1.1.5', 'e', 1),
   ('1', '1.1.6', 'f', 1),
   ('1', '1.1.7', 'g', 1),
   ('1', '1.1.8', 'h', 1),
   ('1', '1.1.9', 'i', 1),
   ('1', '1.1.10', 'j', 1),
   ('1', '1.1.11', 'k', 5),
   ('1', '1.1.12', 'l', 5),
   ('1', '1.1.13', 'm', 5),
   ('1', '1.1.14', 'n', 5),
   ('1', '1.1.15', 'o', 5),
   ('1', '1.1.16', 'p', 5),
   ('1', '1.1.17', 'q', 5),
   ('1', '1.1.18', 'r', 5),
   ('1', '1.1.19', 's', 5),
   ('1', '1.1.20', 't', 5),
   ('1', '1.1.21', 'u', 9),
   ('1', '1.1.22', 'v', 9),
   ('1', '1.1.23', 'w', 9),
   ('1', '1.1.24', 'x', 9),
   ('1', '1.1.25', 'y', 9),
   ('1', '1.1.26', 'z', 9),
   ('2', '1.1.1', 'a', 2),
   ('2', '1.1.2', 'b', 2),
   ('2', '1.1.3', 'c', 2),
   ('2', '1.1.4', 'd', 2),
   ('2', '1.1.5', 'e', 2),
   ('2', '1.1.6', 'f', 2),
   ('2', '1.1.7', 'g', 2),
   ('2', '1.1.8', 'h', 2),
   ('2', '1.1.9', 'i', 2),
   ('2', '1.1.10', 'j', 2),
   ('2', '1.1.11', 'k', 6),
   ('2', '1.1.12', 'l', 6),
   ('2', '1.1.13', 'm', 6),
   ('2', '1.1.14', 'n', 6),
   ('2', '1.1.15', 'o', 6),
   ('2', '1.1.16', 'p', 6),
   ('2', '1.1.17', 'q', 6),
   ('2', '1.1.18', 'r', 6),
   ('2', '1.1.19', 's', 6),
   ('2', '1.1.20', 't', 6),
   ('2', '1.1.21', 'u', 10),
   ('2', '1.1.22', 'v', 10),
('2', '1.1.23', 'w', 10),
('2', '1.1.24', 'x', 10),
('2', '1.1.25', 'y', 10),
('2', '1.1.26', 'z', 10),
('3', '1.2.1', 'a', 3),
('3', '1.2.2', 'b', 3),
('3', '1.2.3', 'c', 3),
('3', '1.2.4', 'd', 3),
('3', '1.2.5', 'e', 3),
('3', '1.2.6', 'f', 3),
('3', '1.2.7', 'g', 3),
('3', '1.2.8', 'h', 3),
('3', '1.2.9', 'i', 3),
('3', '1.2.10', 'j', 3),
('3', '1.2.11', 'k', 7),
('3', '1.2.12', 'l', 7),
('3', '1.2.13', 'm', 7),
('3', '1.2.14', 'n', 7),
('3', '1.2.15', 'o', 7),
('3', '1.2.16', 'p', 7),
('3', '1.2.17', 'q', 7),
('3', '1.2.18', 'r', 7),
('3', '1.2.19', 's', 7),
('3', '1.2.20', 't', 7),
('3', '1.2.21', 'u', 11),
('3', '1.2.22', 'v', 11),
('3', '1.2.23', 'w', 11),
('3', '1.2.24', 'x', 11),
('3', '1.2.25', 'y', 11),
('3', '1.2.26', 'z', 11),
('4', '1.2.1', 'a', 4),
('4', '1.2.2', 'b', 4),
('4', '1.2.3', 'c', 4),
('4', '1.2.4', 'd', 4),
('4', '1.2.5', 'e', 4),
('4', '1.2.6', 'f', 4),
('4', '1.2.7', 'g', 4),
('4', '1.2.8', 'h', 4),
('4', '1.2.9', 'i', 4),
('4', '1.2.10', 'j', 4),
('4', '1.2.11', 'k', 8),
('4', '1.2.12', 'l', 8),
('4', '1.2.13', 'm', 8),
('4', '1.2.14', 'n', 8),
('4', '1.2.15', 'o', 8),
('4', '1.2.16', 'p', 8),
('4', '1.2.17', 'q', 8),
('4', '1.2.18', 'r', 8),
('4', '1.2.19', 's', 8),
('4', '1.2.20', 't', 8),
('4', '1.2.21', 'u', 12),
('4', '1.2.22', 'v', 12),
('4', '1.2.23', 'w', 12),
('4', '1.2.24', 'x', 12),
('4', '1.2.25', 'y', 12),
('4', '1.2.26', 'z', 12);

Query:

  SELECT `ip` , `oid` , `element`
    FROM `test`
ORDER BY `temp` ASC , `ip` ASC , `oid` ASC
   LIMIT 999

The following select query returns the desired result
now just need to figure out how to remove the temp column and create a select query that generates the same or similar result.

Any help would be appreciated

  • 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-16T07:48:51+00:00Added an answer on May 16, 2026 at 7:48 am

    Need to have the returned results in groups of up to 10 items per ip address and then going to the next IP address and return up to 10 more and so on and when one pass through all the IP addresses is complete go back to the first IP and return the second group of up to 10, next IP and 10 and so on.

    MySQL unfortunately does not support the ROW_NUMBER() function that most other brands of database support, but you can simulate it with a user variable.

    The following is tested with your data and MySQL 5.1.49:

    SET @rownum := 0;
    SET @ip := null;
    
    SELECT * FROM (
        SELECT IF(@ip=ip,@rownum:=@rownum+1,@rownum:=0) AS rownum, @ip:=ip AS ip, oid
        FROM test ORDER BY ip, oid
    ) AS t
    ORDER BY FLOOR(rownum/10), ip, oid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following query does not return any result SELECT user_id FROM test WHERE poll_id
I have Two SQL Query Both Return select round(convert(float,'24367.723'),2) Result:24367.72 Second: select convert(varchar(20),round(convert(float,'24367.723'),2)) Result:24367.7
JPQL queries can return custom result objects with the NEW operator: SELECT NEW myPackage.MyVO(e.fieldX,
SQL server 2008 Hello here is my query which returns the result SELECT *
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
How do I do a join that would return me results similar to- SELECT
I need a Java function that returns the results of a SQL SELECT query
I want to remove duplicate rows return from a SELECT Query in Postgres I
The following two queries return the same (expected) result when I query my database:
This query: select * from op.tag where tag = 'fussball' Returns a result which

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.