mysql> show create table table1;
+--------+----------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+----------------------------------------------------------------------------------------+
| table1 | CREATE TABLE `table1` (
`id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+--------+----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show create table table2;
+--------+----------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+----------------------------------------------------------------------------------------+
| table2 | CREATE TABLE `table2` (
`id` char(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+--------+----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select t1.id, t2.id from table1 t1 join table2 t2 on ((ord(t2.id) - 97) = (t1.id - 1) % (select count(*) from table2)) group by t1.id;
+----+----+
| id | id |
+----+----+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | a |
| 5 | b |
| 6 | c |
+----+----+
6 rows in set (0.00 sec)