I have the following tables : client and shop. They have the following columns :
Client : Id, Name, Surname, Email
Shop : Id, Name, ClientId
ClientId is a foreign key to table Client.
I need to do a search based on the name AND surname OR Email and if there is any entry in the Shop table then return it but should not return the Id passed as parameter.
I have tried using a left join as follows but this does not work:
select *
from Client c
left join Shop s
on c.Id = s.ClientId
where c.Name = 'abc'
and c.Surname = 'xyx'
and c.Id != Id
or c.Email = 'ab@cde.com'
and c.Id != Id
But this is not returning me the correct data.
For example, I want to seach the name Jon and surname Sam with email
jon@samy.com and clientId = 201.
So the request should return me all client having the name Jon and surname Sam or having email jon@samy.com
and if there is any entry with these details in the table Shop return it but excluding client with Id 201.
I would also like to convert this SQL to LinQ.
Any idea what is wrong with my request?