I have two tables which I want to query at the same time. I'm thinking
something along the lines of

SELECT c.categoryid, sc.sub_CategoryId
FROM categories c, sub_category sc
WHERE c.category = '#form.searchVal#' OR sc.sub_Category =
'#form.searchVal#'
LIMIT 1

But where this is a left join it will always return a result for either
column whether it makes a match or not.

I could do something like the code below, but it seems to cumbersum for the
job.
<cfquery name="qryName">
SELECT c.categoryid AS catId
FROM categories c
WHERE c.category = '#form.searchVal#'
</cfquery>

<cif NOT qry.recordCount>
<cfquery name="qryName">
SELECT sc.sub_CategoryId AS catId
FROM sub_category sc
WHERE sc.sub_Category = '#form.searchVal#'
</cfquery>
</cfif>

<cfset variables.catId =  qryName.catId>

Cheers

Andy

---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.735 / Virus Database: 489 - Release Date: 06/08/2004
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to