using INTERSECT/JOIN on same table in a loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sunaina

    #1

    using INTERSECT/JOIN on same table in a loop

    I am doing the following query using intersect but gives me an error
    'error in sql syntax. I tried using join as well but gives me
    similar error. In the following code still has intersect just to show
    exactly what I want to do. My query in mysql console is working
    without using intersect or join.

    $query_objects = "";

    for ($i=0; $i<$num_questio ns; $i++) {
    if ($i != 0)
    $query_objects = " intersect ";
    $query_objects = $query_objects .
    "select distinct obj from answer where qid=" .
    $asked_question s[$i] .
    " and ans=" . $asked_answers[$i];

    }
  • Bill Karwin

    #2
    Re: using INTERSECT/JOIN on same table in a loop

    sunaina wrote:[color=blue]
    > I am doing the following query using intersect but gives me an error
    > 'error in sql syntax. I tried using join as well but gives me
    > similar error. In the following code still has intersect just to show
    > exactly what I want to do. My query in mysql console is working
    > without using intersect or join.[/color]

    Print the final string you have built, after the loop is done. Syntax
    errors are often more apparent when you look at the actual string, not
    the code that produces it.

    Bill K.

    Comment

    Working...