• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

query a query

Explorer ,
Jul 09, 2010 Jul 09, 2010

Copy link to clipboard

Copied

I am having a nightmare with this query. I am trying to use the results from 1 query and then use it in the second but it will only give me 1 result when the it should give me 5.  The first query returns 5 ids so the second should give me the same

<cfquery name="getquote" datasource="conveyancingshoppers">
select solicitorsid from UUID
where UUID='#UUID#'
</cfquery>
<cfoutput query="getquote
">
       
<CFQUERY name="getname" datasource="conveyancingshoppers">
    SELECT *
  FROM solicitors
  WHERE solicitorsid = #getquote.solicitorsid#

</CFQUERY>
</cfoutput>

I have tried so many different ways and cannot get it to work. In the second query i want to be able to select solicitorsid from the tables solicitors and fees.

Please help me fix this

TOPICS
Advanced techniques

Views

662

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 09, 2010 Jul 09, 2010

Copy link to clipboard

Copied

I hear great things about books like "Teach yourself SQL in 10 minutes".

Did you try

<cfquery name="getquote" datasource="conveyancingshoppers">
     SELECT * 'this is a very bad habit

     FROM solicitors INNER JOIN uuid ON (solicitors.solicitorsid = uuid.solicitorsid)
     WHERE UUID='#UUID#'
</cfquery>

<cfdump var="#getQuote#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2010 Jul 09, 2010

Copy link to clipboard

Copied

Ian gave you the best available answer for situations where the two tables have the same datasource.  If they don't, you might still need the book Ian mentioned.  Instead of the equal sign, you use the sql keyword "in".

The coldfusion valuelist() function will also come in handy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

Thanks that works for the 2 tables but i need to add another I have tried

<cfquery name="getquote1" datasource="conveyancingshoppers">
     SELECT *
     FROM solicitors INNER JOIN uuid ON (solicitors.solicitorsid = uuid.solicitorsid)
  INNER JOIN uuid ON (fees.solicitorsid = uuid.solicitorsid)
     WHERE UUID='#UUID#'
</cfquery>

but it gives me the error

Error Executing Database Query.

[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '(solicitors.solicitorsid = uuid.solicitorsid) INNER JOIN uuid ON (fees.solicitorsid = uuid.solicitorsid)'.

Is there something else i need

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

<cfquery name="getquote1" datasource="conveyancingshoppers">
   SELECT *
   FROM solicitors INNER JOIN

        uuid ON (solicitors.solicitorsid = uuid.solicitorsid)INNER JOIN

        fees ON (fees.solicitorsid = uuid.solicitorsid)
   WHERE UUID='#UUID#'
</cfquery>

You had linked the uuid table twice and not linked the fees table in your FROM clause.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

This should not affect the results at all, but since the UUID table seems to be the driving table of this query, I would probably right it this way to be a little more clear.

<cfquery name="getquote1" datasource="conveyancingshoppers">
   SELECT *
   FROM uuid INNER JOIN
       
solicitors ON (uuid.solicitorsid = solicitors.solicitorsid)INNER JOIN
        fees ON (uuid.solicitorsid = fees.solicitorsid)
   WHERE UUID='#UUID#'
</cfquery>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2010 Jul 12, 2010

Copy link to clipboard

Copied

LATEST

I have worked out how to completed it

<cfquery name="getcombined" datasource="conveyancingshoppers">
SELECT s.*,f.*,u.*
FROM solicitors s, fees f , UUID u
WHERE u.UUID='#UUID#'
AND u.solicitorsid = s.solicitorsid
AND s.solicitorsid = f.solicitorsid

</cfquery>

thanks for you help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation