似乎没有内部连接,它给了我不同的值,但有了它,它显示了所有这些。为什么不能给我明确的价值观呢?
她的代码:
SELECT DISTINCT
m.manager_account_id
, first_name
, last_name
, m.active
, m.user_name
, d.department_name
FROM tbl_Manager_Accounts m
LEFT OUTER JOIN tbl_Manager_App_Link mal ON m.manager_account_id = mal.manager_account_id
LEFT OUTER JOIN tbl_Application a ON a.application_id = mal.application_id
INNER JOIN tbl_Department d on a.department_id=d.department_id
WHERE a.department_id = @department_id and m.user_name not like '%admin%'
OR m.department_id = @department_id and m.user_name not like '%admin%'
ORDER BY last_name
我的manager_id正在出现:
383 381 381 381 2877 382 2876 435 435 435 435 435 435
答案 0 :(得分:1)
每ManagerId
只能生成一行,并且仍然显示您想要的所有其他字段。当连接表中有多行用于同一个{{1}时,计算机要做什么} ??应该猜?
如果需要在另一个表中显示多个行(具有不同值)的数据,那么您需要指定要提取的值。您可以使用ManagerID
或Min
等聚合函数和Max
,如下所示:
group By
答案 1 :(得分:0)
只有选择m.manager_account_id才能解决您的问题。
更正后的查询:
SELECT DISTINCT
m.manager_account_id
FROM tbl_Manager_Accounts m
LEFT OUTER JOIN tbl_Manager_App_Link mal ON m.manager_account_id = mal.manager_account_id
LEFT OUTER JOIN tbl_Application a ON a.application_id = mal.application_id
INNER JOIN tbl_Department d on a.department_id=d.department_id
WHERE a.department_id = @department_id and m.user_name not like '%admin%'
OR m.department_id = @department_id and m.user_name not like '%admin%'
ORDER BY last_name