m11oct Posted September 13, 2006 Share Posted September 13, 2006 If you don't know about MySQL syntax then please just ignore this post... I'm having a MySQL Query problem as I don't know how to write it... I want to select columns B and C from TABLE2 if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all. Column A is the index for TABLE1 and column B is the index for TABLE2 while column C in TABLE2 refers to a row from TABLE1. However, it appears there are quite a lot of cases in TABLE2 where the row column C referes to in TABLE1 no longer exists and I'd like to be able to select all of these. Any ideas? Link to comment https://forums.phpfreaks.com/topic/20599-select-from-one-table-if-index-doesnt-exist-in-another-table/ Share on other sites More sharing options...
shoz Posted September 13, 2006 Share Posted September 13, 2006 [quote=m11oct]if the value from C in TABLE1 doesn't exist as a column A in TABLE1 at all.[/quote]Did you mean C in TABLE2?[code]SELECTtable2.B, table2.CFROMtable2LEFT JOIN table1ONtable2.C = table1.AWHEREtable1.A IS NULL[/code]http://dev.mysql.com/doc/refman/4.1/en/join.html Link to comment https://forums.phpfreaks.com/topic/20599-select-from-one-table-if-index-doesnt-exist-in-another-table/#findComment-90954 Share on other sites More sharing options...
m11oct Posted September 14, 2006 Author Share Posted September 14, 2006 That works well, thank you very much. Link to comment https://forums.phpfreaks.com/topic/20599-select-from-one-table-if-index-doesnt-exist-in-another-table/#findComment-91953 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.