Consider the following SQL query:
SELECT
friends.name as friendname,
friends.surname as friendsurname,
friends.number as friendnumber,
friends.gender as friendgender,
clients.name as clientname,
clients.surname as clientsurname
FROM friends
INNER JOIN clients
ON friends.clientid = clients.id
WHERE datetime(friends.creationdate, 'localtime') >= datetime('SOME_TEST_TIME') AND datetime(friends.creationdate, 'localtime') <= datetime('SOME_TEST_TIME')
Both the friends and clients tables have a number column that I want to compare in this query: IF friends.number is already in clients' table (clients.number column) then don't select that particular row anymore.
How is it possible to accomplish this in one query?
Example:
Table clients:
--------------------------
id name surname number
1 john smith 55555
2 sam wesker 12345
3 adam Nye 48745
--------------------------
Table friends:
----------------------------------
id name surname number clientid
1 abcd qwert 88888 2
2 dddd asdfg 48745 2
3 ffff zxcvb 77777 3
----------------------------------
The query should omit the second row in friends because its number is present in clients' table