left join to insert

arkiboys 9,686 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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,670 questions
{count} votes

Accepted answer
  1. Olaf Helper 44,296 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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