Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2003
    Location
    China
    Posts
    54

    Unanswered: Newby error in SQL syntax "where" clause

    Hi,

    I have the below syntax that is throwing up the following error when I run the query:

    Unknown column 'conid' in 'where clause'

    Here is the syntax:
    -------------------------------------------
    SELECT jos_content.id AS conid,
    jos_jreviews_content.contentid AS jrconid,
    FROM jos_content, jos_jreviews_content
    WHERE conid = jrconid
    ORDER BY jos_content.id ASC
    ----------------------------------------------

    I am using Navicat to edit and run. Thanks for anyone's help.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT jos_content.id AS conid
         , jos_jreviews_content.contentid AS jrconid 
      FROM jos_content
    INNER
      JOIN jos_jreviews_content
        ON jos_jreviews_content.contentid = jos_content.id
    ORDER 
        BY jos_content.id ASC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Using your own syntax:

    Code:
    SELECT jos_content.id AS conid,
    jos_jreviews_content.contentid AS jrconid,
    FROM jos_content, jos_jreviews_content
    WHERE conid = jrconid
    ORDER BY jos_content.id ASC
    The where clause must use the field name and not the renamed field name

    Code:
    SELECT jos_content.id AS conid,
    jos_jreviews_content.contentid AS jrconid,
    FROM jos_content, jos_jreviews_content
    WHERE jos_content.id = jos_jreviews_content.contentid
    ORDER BY jos_content.id ASC
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by it-iss.com View Post
    The where clause must use the field name and not the renamed field name
    correct

    but don't forget to remove the dangling comma

    and JOIN syntax is more better

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Nice spot Rudy!!
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  6. #6
    Join Date
    Apr 2003
    Location
    China
    Posts
    54
    Thanks for all your help. This works!

Posting Permissions

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