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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help w- join query

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have two tables, one includes new data to be imported into a second table. I want to flag records in the second table with matching key fields as inactive, prior to importing the new data.

My join looks like this:
Code:
SELECT table_2.rec_no
FROM table_2
LEFT JOIN table_1
ON table_2.key=table_1.key
WHERE
table_2.key IS NOT NULL

But the result is always the complete contents of table_2, instead of the matching records. Can someone help me see the error of my ways here?

TIA,

-ADM
 
OK, I got a little ahead of myself- I see the problem.

Issue resolved...

-A
 
I can select the data I wish to update with this query:
Code:
SELECT main_table.rec_no
FROM main_table
LEFT JOIN import_table
ON main_table.key=import_table.key
WHERE
import_table.key IS NOT NULL

But am not updating the selected records correctly...
Still need help. I was trying this:
Code:
UPDATE main_table
set `active` = 'N'
LEFT JOIN import_table
ON main_table.key=import_table.key
WHERE
import_table.key IS NOT NULL

Can someone help me properly combine the update query with my join selection?

Again, thank you.
 
Code:
UPDATE main_table
LEFT JOIN import_table
ON main_table.key=import_table.key
set `active` = 'N'
WHERE
import_table.key IS NOT NULL

did the trick...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top