1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Grouping by two columns in a table

Discussion in 'Databases' started by Norrad, Apr 16, 2018 at 8:37 AM.

  1. #1
    I'm trying to create a very simple messaging system for a website and I am trying to group conversations by from or to using a single SQL statement. I have simplified the statement I am trying to use below:
    $messages_query = "SELECT * FROM tbl_messages WHERE from_id='$current_user' OR to_id='$current_user' GROUP BY from_id, to_id ORDER BY message_date DESC";

    But ofcourse the grouping is a bit off. How would I get it to group by sender/receiver?
    Norrad, Apr 16, 2018 at 8:37 AM IP