SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Iceman90's Avatar
    Join Date
    Mar 2006
    Location
    Calgary, Alberta, Canada
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with my query

    Hello everyone,

    I am trying to write a query for my website that allows users to search for all new communities in our city by the home builders who build in it.

    The way the site works, is a user can select the quadrant of the city, and then up to 2 builders and see the communities they develop in.

    Right now I am using this query:
    Code MySQL:
    SELECT DISTINCT communities.id AS id, communities.url AS url, communities.name AS name, quadrant.name AS quadName, builders.id
    FROM communities, quadrant, builders
    WHERE communities.quadrant =4
    AND communities.quadrant = quadrant.id
    AND builders.id = 9
    ORDER BY name, quadName ASC

    Which correctly pulls the data filtered by a single builder (id#9). However, I can't get the second builder to be passed correctly in the query.

    Code MySQL:
    SELECT DISTINCT communities.id AS id, communities.url AS url, communities.name AS name, quadrant.name AS quadName, builders.id
    FROM communities, quadrant, builders
    WHERE communities.quadrant =4
    AND communities.quadrant = quadrant.id
    AND builders.id = 9 OR builders.id = 1
    ORDER BY name, quadName ASC

    With this, I now get all communities that these 2 builders are in, despite the quadrant. I am hoping someone can help me rewrite this query to do what I need.

    Thanks in advance!

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    AND (builders.id = 9 OR builders.id = 1)
    or more simply
    Code:
    AND builders.id IN (1,9)


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
  •