Linked Questions
70 questions linked to/from What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL?
2 votes
6 answers
7k views
Retrive Records Form One Table as long as they do not exist in Another table T-SQL [duplicate]
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL? I need to wite a query that will retrieve the records from Table A , provided that the key ...
4 votes
1 answer
2k views
Fastest performance with DELETE logic NOT IN nested query [duplicate]
I'm trying to get the fastest performance for this DELETE (and SELECT) query. Is there a better way to DELETE the records, because this takes over 10 minutes to run? I imagine it has to do it's own ...
0 votes
0 answers
59 views
SQL - Not Exists vs JOIN [duplicate]
Both of the following queries work perfectly for me at the moment giving out the same results. Which one of the following two are more preferable for huge databases in the long run? Or say, ...
768 votes
16 answers
1.6m views
How to select all records from one table that do not exist in another table?
table1 (id, name) table2 (id, name) Query: SELECT name FROM table2 -- that are not in table1 already
2219 votes
2 answers
2.3m views
What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? [duplicate]
What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN in MySQL?
650 votes
11 answers
2.0m views
NOT IN vs NOT EXISTS
Which of these queries is the faster? NOT EXISTS: SELECT ProductID, ProductName FROM Northwind..Products p WHERE NOT EXISTS ( SELECT 1 FROM Northwind..[Order Details] od WHERE p....
29 votes
4 answers
76k views
Using a left join and checking if the row existed along with another check in where clause
I have the following tables: Users Banned SELECT u.* FROM Users WHERE u.isActive = 1 AND u.status <> 'disabled' I don't want to include any rows where the user may also be in the ...
12 votes
4 answers
33k views
What's the best way to use LEFT OUTER JOIN to check for non-existence of related rows
Using MySQL 5.x I want to efficiently select all rows from table X where there is no related row in table Y satisfying some condition, e.g. Give me all records in X where a related Y with foo = bar ...
10 votes
5 answers
24k views
MySQL NOT IN from another column in the same table
I want to run a mysql query to select all rows from a table films where the value of the title column does not exist anywhere in all the values of another column (collection). Here is a simplified ...
4 votes
2 answers
10k views
Delete all rows which has no id existing in another table
I want to delete all rows which has no existing foreign key in another table example: table1 +----+-------+ |id | data | +----+-------+ | 1 | hi | +----+-------+ | 2 | hi | +----+-------+ | ...
3 votes
3 answers
7k views
Find records on multiple fields not in another table
Let's say I have 2 tables (tb1, tb2) with both the following schema: CREATE TABLE tb1 ( col1 INT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL, col4 REAL ); How do I find records of tb1 ...
4 votes
5 answers
6k views
How do I select a row from one table where the value row does not exist in another table?
Let's say I have two identical tables, A and B, with the row "x". I want to select all elements in A, where the value of x in A is not in any value of x of B. How do I do that?
2 votes
2 answers
13k views
NOT EXISTS vs NOT IN [duplicate]
I'm optimizing some SQL queries (this could be considered part 2 of a question i recently posted) and replacing some NOT IN with NOT EXISTS predicates Am I right in thinking that the main benefit to ...
1 vote
5 answers
5k views
Difference between two recordsets in TSQL
I am using Microsoft SQL Server 2008 and we have two tables called Applications and Enrolments. I want to know which applications are not converted into the Enrolments. As shown in the following ...
1 vote
4 answers
9k views
How to use WHERE statement in SQL to exclude a group
I have a complex query, but here is the essence of what I'm trying to do In a table looking like this: Col1 Col2 Bill 0 Bill 0 Bill 0 Bill 1 Bill 1 John 1 John 1 Jonh 1 The above ...