Skip to main content
Known Participant
June 15, 2009
Question

Different Datasources and QoQ

  • June 15, 2009
  • 1 reply
  • 582 views

I have to read tables from two different datasources, so I us QoQ

My first query :

<cfquery name="qry1" datasource="db1">

select table1.name,

table1.phone,

table1.empID

from table1

</cfquery>

My second query :

<cfquery name="qry2" datasource="db2">
select table2.empID,

table2.address,

table2.city

from table2

</cfquery>

Then I combine the two using QoQ:

<cfquery name="qry" dbtype="query">

select table1.name,

table1.phone,

tabel1.empId,

table2.address,

tablbe2.city

from table1, table2

where table1.empID = table2.empID

</cfquery>

This works and gives me what I want. Now the requirement is  to find all info from table1 even if there are no mathches, so I have to use left join but QoQ seems very limited and will not allow left joins.

How do I read tables from two different datasoruces and then get all info from one table regardless if it is not in the other table, if my above method is incorrect ? (I just typed this so there could be typos)

Thanks

    This topic has been closed for replies.

    1 reply

    Inspiring
    June 15, 2009

    select whatever

    from query2

    where somefield not in (valuelist(query1.somthing))

    union

    select whatever

    from query2, query1

    where query2.something = query1.something

    Known Participant
    June 16, 2009

    If I just want to combine all the data from both tables, would I just have :

    <cfquery name="qry" dbtype="query">

    select table1.name,

    table1.phone,

    tabel1.empId,

    table2.address,

    tablbe2.city

    from table1, table2

    </cfquery>

    It seems like if I take out the WHERE clause, it does not like it.

    Inspiring
    June 17, 2009

    If you take out the where clause you get a cartesian product.  With Q of Q you have to join your queries in the where clause.