1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Looking for query to find where two members posted in same thread

Discussion in 'General PHP and MySQL Discussions' started by AndyB, Jul 23, 2013.

  1. AndyB

    AndyB Well-Known Member

    I'm looking for query to find where two members posted in same thread. So far I have created this query but it does not retrieve any results.

    SELECT xf_thread.thread_id
    FROM xf_thread
    INNER JOIN xf_post ON xf_post.thread_id = xf_thread.thread_id
    WHERE xf_post.user_id='1'
    AND xf_post.user_id='2'
  2. Jeremy

    Jeremy Well-Known Member

    Your query is looking for a post where the posters ID (xf_post.user_id) is both 1 & 2. This is impossible.
  3. AndyB

    AndyB Well-Known Member

    I posted the question at Stack Overflow and here's the MySQL query that works perfectly.

    SELECT thread_id
    FROM xf_post
    group by thread_id
    having max(user_id='1') > 0
    and max(user_id='2') > 0
    Marcus likes this.
  4. Marcus

    Marcus Well-Known Member

    That's such a cool solution.

Share This Page