Skip to main content
April 5, 2008
Answered

Problem with a Join Query

  • April 5, 2008
  • 3 replies
  • 366 views
Struggling to get my head around this, so would appreciate any help.

I'm running the query below, which includes a join. If I run this query through Navicat (a MySQL GUI, for those that aren't familar) - I get the expected result.

I also have a fairly similar query running on the site elsewhere successfully, so I'm struggling to figure out why it's not working.

The query is;

<cfquery name="getwatched" datasource="#datasource#">
SELECT r.retailer_name, r.id, r.shortname, d.id, d.merchant_id, d.user_id, d.e_updates
FROM cc_watchlists d
LEFT JOIN merchants r
ON d.merchant_id=r.id
WHERE d.user_id=#SESSION.Auth.ID#
ORDER BY r.retailer_name ASC
</cfquery>

and the output;

<cfoutput query="getwatched">
<dt><a href="page.cfm?for=#shortname#">#retailer_name#</a></dt>
</cfoutput>

The error states;

coldfusion.runtime.UndefinedVariableException: Variable SHORTNAME is undefined.

I'd be grateful of any help!
This topic has been closed for replies.
Correct answer Newsgroup_User
Do a <cfdump> of the whole query just before the line that's erroring, and
make sure it contains what you think it contains.

--
Adam

3 replies

April 5, 2008
I made some changes setting some 'AS' to the query, which sorted out the multiple ID's, and that seems to have done the trick.

Everything working now :-)

Thanks for the suggestion Adam, I never would have figured it out otherwise!
April 5, 2008
Adam,

Thanks for replying. I've done the <cfdump> and the shortname variable is there.

One thing I did notice however is that the various IDs all have the same number (they should be different). Not sure if that is a seperate issue though?
Newsgroup_UserCorrect answer
Inspiring
April 5, 2008
Do a <cfdump> of the whole query just before the line that's erroring, and
make sure it contains what you think it contains.

--
Adam