SELECT u.idu, b.idu , b.idb FROM users u LEFT JOIN banned b ON ((b.idu = $idu OR b.idb = $idu) AND (u.idu = b.idu OR u.idu = b.idb)) WHERE ( (b.idu IS NULL) AND (b.idb IS NULL)) ORDER BY RAND() LIMIT 1