Q:

MYSQL "every row excluded, but only once" join

Imagine a dance party where we line up boys on one side and girls on the other. Each boy is placed into table A, once and only once. Likewise for the girls in table B.
We then want to match up the boys in A once and only once with a girl in B, and likewise the girls in B need to match with one and only one boy in A.
A would have an ID column as a primary key and a b_id that would hold the ID of the girl they were matched with, or NULL if not yet matched.
B would have the same for the girls.
Tables would look like this:
table A (boys)
---------
|id|b_id|
---------
| 1|NULL|
| 2|NULL|
| 3|NULL|
| 4|NULL|
| 5|NULL|
| 6|NULL|
---------

table B (girls)
---------
|id|a_id|
---------
| 1|NULL|
| 2|NULL|
| 3|NULL|
| 4|NULL|
| 5|NULL|
| 6|NULL|
---------

What type of query would match one and only one boy with one and only one girl that is not yet matched? Results would look something like this:
results
-------------------------
|a.id|a.b_id|b.id|b.a_id|
-------------------------
|   1| NULL |   1| NULL |
|   2| NULL |   2| NULL |
|   3| NULL |   3| NULL |
|   4| NULL |   4| NULL |
|   5| NULL |   5| NULL |
|   6| NULL |   6| NULL |
-------------------------

I can get these results by using a temp table with unique indexes, but I'm looking for a query to give me the results without a temp table as the real application of this query is going against millions of rows on both sides.

A:

SELECT boyUnmatched.id  AS aid
     , NULL             AS b_id   --- you really don't need these two
     , girlUnmatched.id AS bid 
     , NULL             AS a_id   --- columns, do you?
FROM
    ( SELECT @rownuma := @rownuma+1 AS rank
           , id 
      FROM a
         , (SELECT @rownuma :=0) AS dummy
      WHERE b_id IS NULL
      ORDER BY id
    ) AS boyUnmatched
  JOIN
    ( SELECT @rownumb := @rownumb+1 AS rank
           , id 
      FROM b
         , (SELECT @rownumb :=0) AS dummy
      WHERE a_id IS NULL
      ORDER BY id
    ) AS girlUnmatched
  ON boyUnmatched.rank = girlUnmatched.rank

