title: How to select distinct rows from a table without a primary key
body: <p>I need to show a Notification on user login if there is any unread messages. So if multiple users send (5 messages each) while the user is in offline these messages should be shown on login. Means have to show the last messages from each user.</p>
  
  <p>I use joining to find records.</p>
  
  <p>In this scenario Message from User is not a primary key.</p>
  
  <p>This is my query</p>
  
  <pre><code>SELECT 
     UserMessageConversations.MessageFrom,  UserMessageConversations.MessageFromUserName,
     UserMessages.MessageTo, UserMessageConversations.IsGroupChat, 
     UserMessageConversations.IsLocationChat, 
     UserMessageConversations.Message, UserMessages.UserGroupID,UserMessages.LocationID 
  FROM    
     UserMessageConversations 
  LEFT OUTER JOIN
     UserMessages ON UserMessageConversations.UserMessageID = UserMessages.UserMessageID 
  WHERE
     UserMessageConversations.MessageTo = 743  
     AND UserMessageConversations.ReadFlag = 0
  </code></pre>
  
  <p>This is the output obtained from above query.</p>
  
  <p><img src="https://i.stack.imgur.com/A9v96.png" alt="enter image description here"></p>
  
  <p>MessageFrom -582 appears twice. I need only one record of this user.</p>
  
  <p>How is it possible</p>