MySQL Forums
Forum List  »  MySQL Workbench

How Do I Cycle Through a Column in MySQL?
Posted by: Abubakar Popoola
Date: November 10, 2022 04:00PM

Assume I have two tables as follows:

CREATE TABLE Example_Table(
`Number` INT PRIMARY KEY,
`Letter` CHAR(1));

CREATE TABLE Adder(
`Number` INT PRIMARY KEY,
`Value` INT);
And I input them with values as such

INSERT INTO Example_Table VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d');
INSERT INTO Adder VALUES (1,3),(2,6),(3,1),(4,2);


I want to cycle through the Example_Table.Number column by adding the Values in the Adder table. I want to create a select statement to extract the primary keys of the resulting sums, but only within the range of the values under the Example_Table.

For example, I will add 3 (the first value under Adder) to the 1 under Example_Table.Number, giving a new value of 4 which the SELECT statement will call upon. There's no issue there. I then add the 6 (under Adder) to the 2 under Example_Table, giving a new value of 8. However, since 8 doesn't exist within the table, I'd like it to simply count 6 (so 3,4,1,2,3,4) and then cycle back to 4.

Any advice on how this could be done, please?

Options: ReplyQuote


Subject
Views
Written By
Posted
How Do I Cycle Through a Column in MySQL?
511
November 10, 2022 04:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.