Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing two tables

Status
Not open for further replies.

8ginga8

Programmer
Dec 14, 2004
54
CA
Hi everyone,

I need to compare to tables. one being the master and the other being a local table.

the master can have hundreds of records and the local have only a few. I need to compare the local to the master and display the ones that are the same and also display the ones that do not exist for the purpose of updating and adding to the master table.

Example:
MASTERTABLE
1,2,3,4,5

LOCALTABLE
1,2,3,4,5,6

OUTPUT
update 1,2,3,4,5
insert 6

hope someone can help

Thanks
 
for update
select * from localTable
where exists (select * from masterTable
where masterTabl.somePK = localTable.somePK)


for insert
select * from localTable
where not exists (select * from masterTable
where masterTabl.somePK = localTable.somePK)

hope it helps..

 
can this same thing be done if the tables that I am trying to compare are in two seperate databases
 
here is what I have

database 1 = local_groups
database 2 = master_groups
primary key in both tables = gr_local_id

<cfquery datasource="local_groups" name="get_local">
SELECT gr_local_id
FROM [GROUP]
where exists (select gr_local_id from groups_master.group
where gr_local_id = group.gr_local_id)

</cfquery>

this is not working
 
what's 'not working'? do you get an error message ?
you wrote your database names are master_groups and local_groups, and you are using something like
[Group] and groups_master.group (?) i don't understand why...

 
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Could not find file 'C:\CFusionMX7\db\slserver54\logging\groups_master.mdb'.

The error occurred in C:\CFusionMX7\ line 39

37 : <br />
38 : <table>
39 : <cfquery datasource="local_groups" name="get_local">
40 :
41 :
 
the error you are getting has nothing to do with the query. your dB does not exist.
'C:\CFusionMX7\db\slserver54\logging\groups_master.mdb'.
groups_master.mdb'

Please go to this folder, C:\CFusionMX7\db\slserver54\logging\ and create groups_master.mdb .

hope it helps



 
can this same thing be done if the tables that I am trying to compare are in two seperate databases"

Not if they are only accessable through two seperate DSNs


Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top