please note question below mysql . imagine table called cars following structure ( we can ignore lack of proper key constraints, etc. not relevant question ): create table cars ( id integer, maker_id integer, status_id integer, notes varchar(100) ); now imagine loading test data this: insert cars (id, maker_id, status_id, notes) values (1, 1001, 0, 'test1'), (2, 1001, 0, 'test2'), (3, 1001, 0, 'test3'), (4, 1002, 0, 'test4'), (5, 1002, 0, 'test5'), (6, 1002, 1, 'test6'), (7, 1002, 1, 'test7'), (8, 1002, 2, 'test8'), (9, 1003, 3, 'test9'), (10, 1003, 3, 'test10'), (11, 1003, 4, 'test11'), (12, 1003, 4, 'test12'), (13, 1003, 5, 'test13'), (14, 1003, 5, 'test14') there 14 records, 3 distinct values in maker_id (1001, 1002, 1003), , 6 distinct values in status_id (0,1,2,3,4,5). now, imagine taking distinct pairs of ( maker_id , status_id ). select ...