SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What seems like a very silly "AND" SQL error [solved]

    I have a very simple MySQL query and the "AND" is breaking the query. If I remove "pt.country_id = $country_id" the query executes. Or if I remove "pt.procedure_id = $procedure_id" the query executes. If they are both together with the AND statement, it breaks...???

    Here is my query:
    Code SQL:
    SELECT d.row_name FROM DATA AS d
    				LEFT JOIN procedure_table AS pt
    				  ON pt.table_id = d.table_id
    				WHERE pt.country_id = $country_id AND pt.procedure_id = $procedure_id

    Here is the error:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' AND pt.procedure_id = 1' at line 4
    Here is my table structure:
    Attached Images Attached Images

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Echo the query so you can see how it looks like with the values instead of the variables. My guess is one of them is empty.

    Another thing, if you put WHERE conditions on the second table, the LEFT JOIN becomes an INNER JOIN. So if that's what you want, use INNER JOIN. If not, put those conditions in the ON clause.

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, that was it, a variable was empty


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
  •