SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More joining problems

    Hi there

    Moving on from my previous thread, I have something a little more urgent to resolve... Like before, I have a table of members and a table of member contacts to link members together. The member contacts table contains the id's of the member but a particular members id can be either column 1 or 2 which is what is causing my joining problem.

    I need a basic list of member contacts, so I need to retrieve a list containing the name and id of all members linked to a given member. Therefore, I need to query the member_contacts table and join the members table. However, I'm struggling to join the members table as I can join on either the column 1 or column 2.

    Any help would be very much appreciated

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, this query seems to work, but is there a much better way of writing it?
    Code:
    SELECT
    	m.member_id,
    	m.firstname,
    	m.lastname
    FROM
    	members m,
    	members_contacts mc
    WHERE
    (
    	mc.member_id = $memberid
    	AND
    	m.member_id = mc.contact_member_id
    )
    OR
    (
    	mc.contact_member_id = $memberid
    	AND
    	m.member_id = mc.member_id
    )
    Thanks again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •