Hello i have a Mysql statement that supposes to return to results.

The statement is

SELECT c.user_one,c.user_two,c.c_id,r.reply
 FROM conversation_reply r
JOIN conversation c ON r.c_id_fk = c.c_id 
 WHERE c.user_one = '3'
 OR c.user_two = '3'
 GROUP BY r.reply

I have only two records in the table so the result should be:

   user_one   user_two   c_id     reply

     2          1         43     Hello One
     1          2         43     Hello Two 

Instead its like

    user_one   user_two   c_id     reply

     2          1         43     Hello One
     2          1         43     Hello Two 

If i loose the GROUP BY it returns 4 records but i only have two, like this

    user_one   user_two   c_id     reply

     1          2         43     Hello One
     2          1         43     Hello Two 
     1          2         43     Hello One
     2          1         43     Hello Two 

Any idea why?

Because you are only grouping on r.reply. Since there are only two differect replies,

With what you've shown the group by could be GROUP BY c.user_one, c.user_two, c.c_id, r.reply and you'll get your expected result. I cannot predict the impact on the rest of your data though.

Another way to eliminate dupes is to SELECT DISTINCT c.user_one,c.user_two,c.c_id,r.reply and remove the GROUP BY altogether.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.