Reputation: 117
I have two tables with phone numbers.
I want check if there is new rows in addresbook table that not exist in users table.
As I am newbie with SQL, is this query correct?
SELECT *
FROM addressbook
WHERE NOT EXISTS (
SELECT Phone1
FROM users
WHERE addressbook.phone = users.phone1
)
EDIT: I user MySQL with PHPMyAdmin Interface, sorry for not to specify before
Upvotes: 0
Views: 3411
Reputation: 39477
Seems OK but I would do it like this.
select a.* from addressbook a
left outer join users u on a.phone = u.phone1
where
(u.phone1 is null)
This is simpler and probably faster.
Upvotes: 5
Reputation: 973
In SQL Server your query is
SELECT * from addressbook WHERE Phone NOT in (SELECT Phone1 from users)
Upvotes: 1