我有一张桌子" materiel" (codeM,DATE_D_ACHAT,DATE_FIN_DE_GAR,...,...,)
CODEM
--------------------
1245
25365
354136
452486
53453
543
56354
8752
94685
和表"用户" (CODEU,NOMU,PRENOMU,......)
CODEU
--------------------
163458
354635
569859
58454
65646
86859
和第三个表" utiliser_le_materiel"
CODEM CODEU
-------------------- --------------------
1245 163458
25365 163458
452486 163458
8752 163458
94685 163458
1245 354635
452486 354635
8752 354635
1245 569859
452486 569859
53453 569859
56354 569859
8752 569859
94685 569859
1245 58454
53453 58454
56354 58454
8752 58454
1245 65646
452486 65646
56354 65646
8752 65646
1245 86859
452486 86859
8752 86859
我想选择与所有codeU连接的codeM ... 我怎么能在sql中做到这一点?
我试过了 "从utiliser_le_materiel中选择CODEM,其中codeu in(select codeu from user)"和这个
" SELECT CODEM FROM utiliser_le_materiel GROUP BY CODEM HAVING codeu IN(SELECT Z.CODEU FROM user Z)"
我试图用" MINUS"但我不能!
答案 0 :(得分:0)
你走在正确的轨道上。但是你的having
应该考虑一下。假设联结表中没有重复:
SELECT CODEM
FROM utiliser_le_materiel
GROUP BY CODEM
HAVING count(*) = (select count(*) from user);