Relating queries

Posted on 2006-05-28
Medium Priority
Last Modified: 2013-12-24
Hi- This should be simple for you experts..I hope!

I am pulling results from two different tables. I want the results to relate to each other:

<CFQUERY  NAME="get_products">
      SELECT      *
      FROM       table1
      WHERE active='1'
<CFQUERY  NAME="get_prices">
      SELECT      *
      FROM       table2


<cfoutput query="get_products" startrow=1 maxrows=1>#name#:</cfoutput>
<cfoutput query="get_products" startrow=1 maxrows=1>#description#</cfoutput>
<cfoutput query="get_prices" startrow=1 maxrows=1>#price1#&nbsp; #price2#</cfoutput>

But I want prices in the "get_prices" query to relate to the name and description in the "get_product" query. I'm sure I need a where clause in my second query, that says something like WHERE id (From table1) equals product_id (from table2). But I'm not sure how to do that. Is that clear enough? Thanks!!
Question by:mel150
LVL 18

Accepted Solution

Plucka earned 2000 total points
ID: 16781056

You would normally do this in a join in a single query

<CFQUERY  NAME="get_products">
    SELECT     *
    FROM      table1
    INNER JOIN table2 on table1.productCode = table2.productCode  
    WHERE active='1'


Author Comment

ID: 16781090
Thanks, Plucka- the easy and clearly expressed answer as usual!!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What You Need to Know when Searching for a Webhost Provider
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question