使用自连接显示具有匹配的 UserAccountID 和 ParentUserAccountID 的记录以及不匹配的记录?
show records that has matching UserAccountID and ParentUserAccountID and non matching records using self join?
我想从 UserAccountID 与 ParentUserAccount ID 匹配的数据库中获取数据
这里是 Sql 查询
SELECT Current.Status,
Current.UserID as UserID,
Current.UserAccountID as C_UserAccID,
Current.Implementation_Type as C_ImpType,
Current.ClientID as C_ClientID,
tbl_clients.ClientName,
parent.LastModifiedDate as PLastModifiedDate,
parent.ParentUserAccountID as PUserAccID,
parent.Implementation_Type as PImpType,
parent.IterationNum as PIterationNum,
parent.Description as PDescription,
parent.GSheetID as PGSheetID
FROM tbl_useraccounts AS Current
JOIN tbl_useraccounts AS parent on parent.ParentUserAccountID=Current.UserAccountID
INNER JOIN tbl_clients on Current.ClientID = tbl_clients.ClientID
WHERE Current.UserID ='7'
and Current.Status!='2'
and parent.ParentUserAccountID!=''
and parent.Implementation_Type='4'
order by parent.LastModifiedDate desc
但我还想显示数据库中 C_UserAccID 不等于 PUserAccountID
的数据
任何帮助将不胜感激提前感谢
SELECT Current.Status,
Current.UserID as UserID,
Current.UserAccountID as C_UserAccID,
Current.Implementation_Type as C_ImpType,
Current.ClientID as C_ClientID,
tbl_clients.ClientName,
parent.LastModifiedDate as PLastModifiedDate,
parent.ParentUserAccountID as PUserAccID,
parent.Implementation_Type as PImpType,
parent.IterationNum as PIterationNum,
parent.Description as PDescription,
parent.GSheetID as PGSheetID
FROM tbl_useraccounts AS Current
LEFT JOIN tbl_useraccounts AS parent on
parent.ParentUserAccountID=Current.UserAccountID
INNER JOIN tbl_clients on Current.ClientID =
tbl_clients.ClientID
WHERE Current.UserID ='7'
and Current.Status!='2'
and parent.ParentUserAccountID!=''
and parent.Implementation_Type='4'
order by parent.LastModifiedDate descv
我想从 UserAccountID 与 ParentUserAccount ID 匹配的数据库中获取数据
这里是 Sql 查询
SELECT Current.Status,
Current.UserID as UserID,
Current.UserAccountID as C_UserAccID,
Current.Implementation_Type as C_ImpType,
Current.ClientID as C_ClientID,
tbl_clients.ClientName,
parent.LastModifiedDate as PLastModifiedDate,
parent.ParentUserAccountID as PUserAccID,
parent.Implementation_Type as PImpType,
parent.IterationNum as PIterationNum,
parent.Description as PDescription,
parent.GSheetID as PGSheetID
FROM tbl_useraccounts AS Current
JOIN tbl_useraccounts AS parent on parent.ParentUserAccountID=Current.UserAccountID
INNER JOIN tbl_clients on Current.ClientID = tbl_clients.ClientID
WHERE Current.UserID ='7'
and Current.Status!='2'
and parent.ParentUserAccountID!=''
and parent.Implementation_Type='4'
order by parent.LastModifiedDate desc
但我还想显示数据库中 C_UserAccID 不等于 PUserAccountID
的数据任何帮助将不胜感激提前感谢
SELECT Current.Status,
Current.UserID as UserID,
Current.UserAccountID as C_UserAccID,
Current.Implementation_Type as C_ImpType,
Current.ClientID as C_ClientID,
tbl_clients.ClientName,
parent.LastModifiedDate as PLastModifiedDate,
parent.ParentUserAccountID as PUserAccID,
parent.Implementation_Type as PImpType,
parent.IterationNum as PIterationNum,
parent.Description as PDescription,
parent.GSheetID as PGSheetID
FROM tbl_useraccounts AS Current
LEFT JOIN tbl_useraccounts AS parent on
parent.ParentUserAccountID=Current.UserAccountID
INNER JOIN tbl_clients on Current.ClientID =
tbl_clients.ClientID
WHERE Current.UserID ='7'
and Current.Status!='2'
and parent.ParentUserAccountID!=''
and parent.Implementation_Type='4'
order by parent.LastModifiedDate descv