mysql - SQL query to only select row if specific condition is met -
consider following sql query:
select friends.name friendname, friends.surname friendsurname, friends.number friendnumber, friends.gender friendgender, clients.name clientname, clients.surname clientsurname friends inner join clients on friends.clientid = clients.id datetime(friends.creationdate, 'localtime') >= datetime('some_test_time') , datetime(friends.creationdate, 'localtime') <= datetime('some_test_time')
both friends
, clients
tables have number
column want compare in query: if friends.number
in clients
' table (clients.number
column) don't select particular row anymore. how possible accomplish in 1 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 second row in friends
because number present in clients
' table
add :
and friends.number not in (select clients.number clients)
Comments
Post a Comment