Join the tables together so they are treated like a single table...(assuming
they are join-able)

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

+-----------------------------------------------+
Bryan Love
  Database Analyst
  Macromedia Certified Professional
  Internet Application Developer
TeleCommunication Systems
[EMAIL PROTECTED]
+-----------------------------------------------+

"...'If there must be trouble, let it be in my day, that my child may have
peace'..."
        - Thomas Paine, The American Crisis

"Let's Roll"
        - Todd Beamer, Flight 93

-----Original Message-----
From: Andy J [mailto:[EMAIL PROTECTED]
Sent: Monday, August 09, 2004 4:22 PM
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