寻找不重复记录

时间:2012-07-20 09:33:56

标签: php mysql cakephp

我有两个表,一个称为许可证,一个称为系统。 现在许可证表保留系统ID和许可证类型(完整或试用)。 系统表保存系统mac_address。

现在,一个系统可能拥有多个试用许可证和一个完整许可证。 现在我想找到尚未生成完整版本的系统,并将它们与mac_address一起分组。

请小建议就够了。

3 个答案:

答案 0 :(得分:1)

 select 
    s.*
from
    systems as s 
where
    s.system_id not in 
    (select l.system_id from licenses as l where l.licence_type='full')

答案 1 :(得分:0)

因此,如果我了解您,您需要找到所有未列出“完整”许可证的系统。在纯SQL中,您可以使用LEFT JOIN实现此目的。像

这样的东西
SELECT DISTINCT s.system_id,s.mac_address
FROM systems s
LEFT JOIN licences l ON s.system_id=l.system_id AND l.licence_type = 'full'
WHERE l.licence_id IS NULL

答案 2 :(得分:0)

我真的不明白你的问题,但你不能让其中一个列独一无二吗?

相关问题