Jaynesh Posted July 11, 2011 Share Posted July 11, 2011 Hello I have an sql query which is working perfectly. SELECT DISTINCT dbPosts.post FROM dbPosts LEFT JOIN ( dbUsers, dbFriends, dbPosts_share ) ON ( dbPosts.username_id = dbUsers.id AND (dbPosts.username_id = dbFriends.user_id) OR (dbPosts.username_id = dbFriends.friend_id) ) but when I add an extra column, it duplicates each output several times. SELECT DISTINCT dbPosts.post, dbUsers.username FROM dbPosts LEFT JOIN ( dbUsers, dbFriends, dbPosts_share ) ON ( dbPosts.username_id = dbUsers.id AND (dbPosts.username_id = dbFriends.user_id) OR (dbPosts.username_id = dbFriends.friend_id) ) Why is this happening? Link to comment Share on other sites More sharing options...
gizmola Posted July 11, 2011 Share Posted July 11, 2011 Based on your query, you'll get a row for every unique combination of dbPosts.post + dbUsers.username in the result set. That's how DISTINCT works. Link to comment Share on other sites More sharing options...
fenway Posted July 14, 2011 Share Posted July 14, 2011 Now you're really posting about the same topic multiple times -- topic locked. Link to comment Share on other sites More sharing options...
Recommended Posts