Latest news
Home » SQL » SQL – find records from one table which don’t exist in another

SQL – find records from one table which don’t exist in another

company_services
+----+------+--------------+
| id | name | company_id|
+----+------+--------------+
| 1  | IT services| 102|
+----+------+--------------+
| 2  | hardware| 105|
+----+------+--------------+

company_products
+----+------+--------------+
| id | title| company_id |
+----+------+--------------+
| 1  | Mouse| 101|
+----+------+--------------+
+----+------+--------------+
| 2 | Keyboard| 102|
+----+------+--------------+
SELECT count(*)FROM company_services WHERE company_id NOT IN (SELECT company_id FROM company_products)

Result Count=1
Related Queries

select records from one table that don’t exist in another,
find records in one table that are not in another,
sql find records in one table that are not in another,
delete rows from one table that exist in another,

Leave a Reply

x

Check Also

zend mysql between query

$aEventsSelect = Engine_Api::_()->getItemTable(‘event’)->select(); if(count($aEventIds) > 0){ $aEventsSelect->where(“event_id IN (?)”, $aEventIds); } if( $filter == “past” ...