title: How to get some items and then remove duplicate items?
body: <p>I have a table something like bellow. I want to get number of visits users and roles per day.</p>
  
  <p>tables:</p>
  
  <pre><code>CREATE TABLE #TempUser
  (
    [Id] int NULL,
    [Username] nvarchar(50) NULL
  )
  
  CREATE TABLE #TempRole
  (
    [Id] int NULL,
    [Title] nvarchar(50) NULL
  )
  
  CREATE TABLE #TempUserRole
  (
    [UserId] int NULL,
    [RoleId] int NULL,
    [LastDate] date NULL
  )
  </code></pre>
  
  <p>data:</p>
  
  <pre><code>INSERT INTO #TempUser([Id],[UserName])
  VALUES
  (1,'Marvin'),
  (2,'Tom'),
  (3,'Charli')
  
  INSERT INTO #TempRole([Id],[Title])
  VALUES
  (1,'Admin'),
  (2,'Manager'),
  (3,'Guest')
  
  INSERT INTO #TempUserRole([UserId],[RoleId],[LastDate])
  VALUES
  (1,1,'2019-02-03'),
  (1,2,'2019-02-06'),
  (1,2,'2019-02-03'),
  (3,3,'2019-02-03'),
  (3,1,'2019-02-02'),
  (3,1,'2019-02-03'),
  (2,1,'2019-02-05'),
  (2,1,'2019-02-05'),
  (3,1,'2019-02-03'),
  (1,1,'2019-02-03'),
  (2,1,'2019-02-06'),
  (2,1,'2019-02-03'),
  (1,1,'2019-02-03'),
  (2,1,'2019-02-02'),
  (1,1,'2019-02-03'),
  (2,1,'2019-02-05'),
  (1,1,'2019-02-05'),
  (2,1,'2019-02-03')
  </code></pre>
  
  <p>How do I get number of visits users and roles per day a list of users who have the same "user", "Role", "Date" , "CounterOfDay"? I need output should be look like this:</p>
  
  <pre><code>UserName  Role    Date          CounterOfDay
  
  Charli    Admin   2019-02-02    2
  
  Tom       Admin   2019-02-02    2
  ...
  </code></pre>