我正在使用MySql,请参考http://postimg.org/image/waso0lsnf/查看我的表结构。
我要取department_id
这个enduser_to_department = Y
以及department_to_enduser = Y
。
对于同一department_id.
我试过顺着这条路走,但它只对一排有效。
SELECT `departments`.`department_id`, `departments`.`department`
FROM `custom_forms_departments` , `departments`
WHERE departments.department_id = custom_forms_departments.department_id
AND (`custom_forms_departments`.`enduser_to_department` = 'Y'
OR `custom_forms_departments`.`department_to_enduser` = 'Y')
GROUP BY `departments`.`department_id`
ORDER BY departments.department_id DESC
http://postimg.org/image/waso0lsnf/
编辑:从URL添加图像。
最佳答案
试试这个:
SELECT `department_id`
FROM `custom_forms_departments`
WHERE `enduser_to_department` = 'Y'
AND `department_to_enduser` = 'Y'
GROUP BY `departments`.`department_id`
ORDER BY departments.department_id DESC
编辑:现在不加入。
我刚把
OR
改成了AND
,因为你希望它们都是'Y',然后改变了连接。