Wall 2 Wall Comments (similar to Facebook)

Discussion in 'MySQL' started by chopsticks, Apr 22, 2008.

  1. #1
    I'm having some problems with a query to retrieve data similar to how a wall 2 wall comments area would would (eg, shows the 2 users discussion). Anyway I was able to do it one way but thats with data from just 1 table. On my site comments on users profiles are split into separate tables (an early decision, not sure why).

    For testing I tried it for 2 users whos profile comments are both in the same table using this query:
     SELECT u.user_id, u.username, c.comment_id, c.user_id, c.friend_id, c.time, c.message
    FROM users u, user_comments_a c
    WHERE (
    c.user_id =1
    AND u.user_id = c.friend_id
    AND c.friend_id =2
    )
    OR (
    c.user_id =2
    AND u.user_id = c.friend_id
    AND c.friend_id =1
    )
    ORDER BY time DESC
    LIMIT 20 
    Code (markup):
    Whilst that works fine in that situation with both users sharing the same comments table, how could it be done if the comments are stored in 2 different tables?

    Such as
    • user_comments_a (fields: comment_id, user_id, friend_id, time, message)
    • user_comments_b (fields: comment_id, user_id, friend_id, time, message)
     
    chopsticks, Apr 22, 2008 IP
  2. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    [Extra]

    Sorry, forgot to add that this is for MySQL.
     
    chopsticks, Apr 23, 2008 IP