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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:56:10+00:00 2026-05-23T15:56:10+00:00

Suppose we have a table named SMALLER , with column num_1 and num_2 ,

  • 0

Suppose we have a table named SMALLER, with column num_1 and num_2, both integer type, and some data in it.

It looks like this:

`num_1`  `num_2` 
    1        2
    2        3
    2        8
    3        4
    4        5
        .
        .
        .  Much much much more
        .  

What Im trying to do is expand this table, and then collect all “Smaller” relations.
Such that, the result table should looks like this:

`num_1`  `num_2` 
    1        2
    1        3
    1        4
    1        5
    1        8
    2        3
    2        4
    2        5
    2        8
    3        4
    3        5
    4        5

I appreciate all helps !

Futhermore, what if instead of “smaller” relations, this table just have a “connected” relation, for instance, ‘1’ connected to ‘2’, ‘2’ connected to ‘3’, ‘2’ connected to ‘4’, such that we say 1-2, 1-3, 1-4, 2-3, 2-4.

  • 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-23T15:56:11+00:00Added an answer on May 23, 2026 at 3:56 pm

    A good place to start would be:

    SELECT 
        A.num_1, B.num_2 
    FROM 
        Smaller AS A JOIN Smaller AS B ON (A.num_1 < B.num_2) 
    ORDER BY A.num_1, B.num_2;
    

    Inside your stored procedure, put this into a cursor, iterate over the cursor and for each row do a INSERT IGNORE. Ie:

    DECLARE num1,num2 INT;
    DECLARE done DEFAULT 0;
    DECLARE mycursor CURSOR FOR SELECT # use the select above, im lazy here
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
    
    OPEN mycursor;
    
    my_loop: LOOP
        FETCH mycursor INTO num1, num2;
        IF done THEN
           LEAVE my_loop;
        END IF;
        INSERT IGNORE INTO Smaller VALUES (num1,num2);
    END LOOP;
    

    To answer your updated question, whiles not entirely sure if you mean connected as by means of relations between unique rows (you would need two columns to store this relation, so it would be quite similar). Or if you mean you have one table containing all numbers, and another two column table containing relations between the rows of the first table.

    Or, finally, if you want a table just containing strings with “1-2”, “1-3” etc. If thats the case, I would keep it as two individual columns and just output them as strings using CONCAT when you poll the table 🙂

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

Sidebar

Related Questions

Suppose I have a table of users. Something like: ID integer, USER text, POSITION
Suppose I have a table named [ProductPriceHistory] like the following: HistoryID..ProductCode..EffectDate.... Price.... IsActive...ProductName 1----------11-----------1
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a table . Now, I'm interested in Getting Useful Data Easily.
Suppose I have a table like: create table { id numeric(5,3), code varchar(10) }
Suppose I have a table called 'test', into which there are three columns named
Suppose we have a trigger, named Foo. Foo depends on the T table and
Suppose that I have a column named '$' and in it I have different
Suppose i have a table with columns: Approved, Joining_Date, Period. Approve-String, Joining_Date-DateTime, Period-Integer. Now

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.