I don't know what is actual question, but my problem is given below ::
I have a MySQL table table_name
something like this:
+----+--------+-------+
| id | name | f_key |
+----+--------+--------
| 1 | abcd | 0 |
| 2 | efgh | 0 |
| 3 | ijkl | 0 |
| 4 | mnop | 2 |
+----+--------+-------+
id
is primary key & f_key
is foreign key [reference to id in same table].
SELECT * FROM table_name WHERE id NOT IN (SELECT f_key FROM table_name WHERE f_key !=0);
is there any other good (minimum execution time) MySQL query to get output like this:
+----+--------+-------+
| id | name | f_key |
+----+--------+--------
| 1 | abcd | 0 |
| 3 | ijkl | 0 |
| 4 | mnop | 2 |
+----+--------+-------+
EDIT ::
Try to make query for medium size result of sub query, but the problem is :
EXISTS executes at high speed against IN : when the subquery results is very large.
IN gets ahead of EXISTS : when the subquery results is very small.