Share via

left join to insert

arkiboys 9,711 Reputation points
2023-09-20T08:31:39.54+00:00
hello,
I would like to return all rows from "Logins" which are not present in "tbl_LoginIdCount"
It's just that I run this once and insert into compute."tbl_LoginIdCount"
but then when I run the same query again the select still returns the same rows and does not see tha tthose rows are already in tbl_LoginIdCount

select 
    CURRENT_DATE , count(fl."LoginId"), fl."LatestCode" 
from 
    "Logins" as fl
    left join "tbl_LoginIdCount" as lc on date(fl."LoginTimestamp") = lc."Date" and fl."LatestCode" = lc."Code"
WHERE
    lc."Date" is NULL and lc."Code" is null
group by 
    fl."LatestCode"; 
SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

Olaf Helper 47,621 Reputation points
2023-09-20T08:46:22.78+00:00

Why do you JOIN on column "LoginTimestamp"? If LoginTimestamp changes the JOIN fails and returns the customer again; remove it.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.