samedi 30 avril 2016

randomly select serie of records that never been together in another serie

I have two tables in mysql :

table 1 (id_item, item) = [(1,A) (2,B) (3,C) (4,D) (5,E) (6,F)]

table 2 (id_serie, item) = [(1,A) (1,C) (1,D) (2,A) (2,E) (2,F) ...]

how do i select randomly 3 items from table 1 that have never been together in a serie from table 2, example: A,B,C or C,D,E ... wrong result example: A,C,D (have been together in serie number 1 )

this is my try wich is not working :

Select * from table1 where table1.item not in (select item from table2) order by rand limit 3




Aucun commentaire:

Enregistrer un commentaire