SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query Intersecting Set with Table

    Hi, I'm not a newbie, but apparently I still have lots to learn.

    I have a table of users (users) that can belong to multiple organizations (one to many) so I use a linking table (user_orgs) to link to my organizations table.

    I'm trying to write a query that will allow me to select one or more organizations and display a list of users that belong to at least one of the selected organizations, but unfortunately MySQL doesn't have an INTERSECT to use.

    Ideally I'd like to do an intersect on the set of organizations chosen, i.e., (1, 2, 3) and all the records in the user_orgs linking table that match the chosen organizations.

    Am I making sense?

    Can someone give me a clue what I need to do here? I'm using PHP.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,328
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by npage100 View Post
    Ideally I'd like to do an intersect on the set of organizations chosen, i.e., (1, 2, 3) and all the records in the user_orgs linking table that match the chosen organizations.
    match any, or all three of them?

    just double-checking what you mean by INTERSECT

    because earlier on, you said "at least one of the selected organizations"

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

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
  •