Have you tried union?

SELECT.

UNION

SELECT.

  _____  

From: Andy J [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 10 August 2004 11:22 a.m.
To: CF-Talk
Subject: Is this possible in SQL

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