If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Newby error in SQL syntax "where" clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-11, 23:24
Trumpet Trumpet is offline
Registered User
 
Join Date: Apr 2003
Location: China
Posts: 54
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.
Reply With Quote
  #2 (permalink)  
Old 02-25-11, 02:58
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-25-11, 04:27
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #4 (permalink)  
Old 02-25-11, 05:30
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-25-11, 07:02
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Nice spot Rudy!!
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #6 (permalink)  
Old 02-25-11, 23:43
Trumpet Trumpet is offline
Registered User
 
Join Date: Apr 2003
Location: China
Posts: 54
Thanks for all your help. This works!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On