I have two tables in a database: Table 1 - files: column 1 - ID column 2 - deleted Table 2 - seminar_files column 1- seminar_id column 2 - file_id ID from table 1 and file_id from table 2 are the column that bridges these together. So for example, I may have a file with an ID of "hakurocks" in table 1, and that same 'hakurocks' may appear in table 2. It may appear zero times, one time or many times, but will have a different seminar_id for each time it appears. I want to select all the IDs from from table 1 that aren't in table 2 when seminar_id is equal to 18 (for example). On top of this, I only want to select the files from table one where deleted is set to zero. Anybody got an idea on how to put together this mysql query? I've tried a bunch of different ways, and I either end up with ALL the files from table one, or none!
Hello, Can you try following queries and let me know if its works : select Table1.ID where Table1.ID <> Table2.ID AND Table2.seminar_id = 18 FROM Table1, Table2; Select Table2.file_id where Table.Id=Table2.seminar_ID AND Table1.deleted=0 FROM Table1, Table2;
Have you tried : SELECT * FROM ((SELECT * FROM Table1 WHERE Table1.ID NOT IN (SELECT Table2.ID FROM Table2)) AS Join_Table) WHERE Table1.deleted = 0 or break it into 2 query statement: SELECT * FROM Table1 WHERE Table1.ID NOT IN (SELECT Table2.ID FROM Table2) AS Join_Table & SELECT * FROM Join_Table WHERE ID = 0 ? Goodluck!