I'm using MySQL database and my table structure is as like:
+---------------+----------------+-------------------+
| leave_type_id | leave_type | leave_type_org_id |
+---------------+----------------+-------------------+
| 23 | Casual Leave | 33 |
| 24 | Earn Leave | 0 |
| 33 | Sick Leave | 0 |
| 34 | CL Leave | 0 |
| 35 | PL LEAVE | 23 |
| 42 | EL LEAVE | 0 |
+----------开发者_JAVA百科-----+----------------+-------------------+
and i want to fetch only the unmapped records from my table leave_type, mean which leave_type_id is not present inside the leave_type_org_id like (24, 34, 35, 42) plz send me the query as in reply asap. Thanks.
You could do join on same table like this
select t1.*
from table t1
left join table t2
on t1.leave_type= t2.leave_type_org_id
where t2.leave_type_org_id is null
OR
With sub query
select * from table
where leave_type_id not in
(
select leave_type_org_id from table
)
精彩评论