考虑以下SQL查询:
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')
friends
和clients
表格都有number
列,我想在此查询中进行比较:IF friends.number
已在clients
&# 39;表格(clients.number
列)然后不再选择该特定行。
如何在一个查询中完成此操作?
示例:
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
----------------------------------
查询应省略friends
中的第二行,因为其编号出现在clients
&#39;表