The idea that I need to satisfy is to extract the records from a table that is related to a table generated from a many-to-many relationship, that is, there are three tables, for example there are Customers, SellerClients and Sellers, but from the three tables I only need data from the Client table but in relation to not leaving the clients that already have an assigned vendor.
Try doing this query:
SELECT c.* FROM Clientes c LEFT JOIN VendedorClientes vc ON c.ClienteID != vc.ClienteID WHERE vc.VendedorID = 1;
This query works when there is at least one record in SellerClients where the vendor ID indicated in the WHERE is validated, but it does not work when there are no records that do not have the vendor ID or there are simply no records with that difference.
I imagine that it is understandable that the table that contains the foreign keys of Clients and Sellers is the SellerClients table, but only the Client and SellerClients tables are used, so I hope you can help me with this.
PS: If it's not too much to ask, I'd like you to help me solve this too but using LINQ, I'm working on an ASP.net MVC project right now
To get customers that don't exist in a table, we can simply use the
NOT IN
.