Thursday, October 22, 2009

How to join tables that has two datasources in coldfusion

Hey, did you know that you can join two tables with different datasources in coldfusion. To those people who are searching on how to do that maybe this little tutorial could help.


Example you had a two table with the column name below.
table 1
name: table_sample1
columns:
        column_1
        columna_2,
        columna_3,
        columna_4




table 2
name: table_sample2
columns:
        column_1
        columnb_2,
        columnb_3,
        columnb_4,




Suppose that the common column between table_sample1 and table_sample2 was the column named column_1
create a query for the first table
<cfquery datasource="datasource1" name="table1" >

      SELECT *
      FROM table_sample1

<cfquery >





create a query for the second table
<cfquery datasource="datasource2" name="table2" >

      SELECT *
      FROM table_sample2

<cfquery >



now here is the code for joining the two tables together.
<cfquery dbtype="query" name="joined_tables" >

              SELECT * 
              FROM 
                  table1, 
                  table2
             WHERE 
                 table1.first_name = table2.first_name

<cfquery >


Thats it guys, hope that works for you.








No comments:

Post a Comment

Feeds

Sonic Run: Internet Search Engine javascript, coldfusion, programming, simple programming teckniques, css, html Webfeed (RSS/ATOM/RDF) submitted to http://www.feeds4all.nl Web Development & Design Blogs DigNow.net

Search Engine Optimization and SEO Tools
javascript, coldfusion, programming, simple programming teckniques, css, html