sptrsn Posted May 22, 2011 Share Posted May 22, 2011 During a select statement, I was doing a lookup on the fly, checking to see if there was a matching value in a second table. The tables have become large enough that it's causing huge speed issues. I don't need any data from the second table. I just need to know if a matching value exists. So, I created a "tracking" field in table 1. My plan was to periodically do an update query and simply set a "1" or a "0" in the tracking field in the first table, IF there was a matching value in the second table. Then I could just add some conditional formatting or whatever, to have a visual clue that table 2 has data for me. I can't figure out how to do it. I've been searching for examples for two hours and can't seem to figure it out. Could one of you, who are obviously smarter than me, give me a clue how to go about this? I've tried all kinds of retarded stuff. It seems to me that it would be something like this... (but obviously these doesn't work) UPDATE t1 SET `match` = '1' WHERE t1.apn = t2.apn or this update t1 set match ='1' where select * from t1 as t1 join(select * from t2)t2 on t1.apn=t2.apn Quote Link to comment https://forums.phpfreaks.com/topic/237093-help-need-to-update-a-table-if-a-matching-value-is-found-in-another-table/ Share on other sites More sharing options...
fenway Posted May 22, 2011 Share Posted May 22, 2011 update t1 inner join t2 on ( t1.apn=t2.apn ) set t1.match = 1 where (....) Quote Link to comment https://forums.phpfreaks.com/topic/237093-help-need-to-update-a-table-if-a-matching-value-is-found-in-another-table/#findComment-1218668 Share on other sites More sharing options...
sptrsn Posted May 22, 2011 Author Share Posted May 22, 2011 That works beautifully! Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/237093-help-need-to-update-a-table-if-a-matching-value-is-found-in-another-table/#findComment-1218782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.