Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003

    Lightbulb Unanswered: combine operators OR subselect AND temporary table

    hi all
    i have a tab for hotels, specifying location and other specs, such as whether they have a pool or a restaurant etc.
    i want to avoid that searches have few or no results.
    Thus i prefer OR in the "specs" part of the query:
    WHERE pool= 1 OR restaurant= 1 etc.
    Using AND would only give me hotels that have a pool AND
    a restaurant. OR gives me all hotels that have EITHER pool or restaurant.
    I get stuck at the location part of the query.
    I want ONLY hotels of the choosen location to appear in the result.
    When i use ..
    SELECT * FROM hotels WHERE location = 3 AND pool = 1 OR restaurant = 1.
    .. i am unable to keep operators APART..
    OR at the end ALSO gives me hotels that are at location 2,
    AND operator forces ALL result hotels to have a pool.
    Is there a kind of bracket system to control the behavior of operators ?
    MUST i learn subselects, temp tables now ?

  2. #2
    Join Date
    Feb 2003
    Nuremberg, Germany
    I think what u want is simply
    SELECT * FROM hotels WHERE location = 3 AND (pool = 1 OR restaurant = 1);
    use brackets to change the operator predecence. without brackets, AND is evaluated before OR.

  3. #3
    Join Date
    Feb 2003

    thanks frank

    thanks frakn .. danke
    ive been all over the www and could not find a hint about this ....

Posting Permissions

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