Help make a complex query.
In general, there are 3 tables. Contacts, Transactions and Tasks
There are 2 entities in contacts (Customers and companies).
Клиент связан с компанией (не обязательно) Клиент связан со сделкой (не обязательно) Компания связана со сделкой (не обязательно) Контакт связан с задачей (не обязательно) Компания связана с задачей(не обязательно) Сделка связана с задачей (не обязательно) I need to select those contacts that have no task for any of the entities. Suppose if a client does not have a task, but the transaction in which he is having a task, then you do not need to display this contact. If the client has a company that has neither a deal nor a task, then you need to withdraw this company.
Wrote like this, but displays incorrectly.
SELECT c.sid FROM `contacts` c left JOIN `link_contacts_leads` lcl ON c.id = lcl.contact_id left JOIN `leads` l ON l.id = lcl.lead_id left JOIN tasks t ON t.el_id = c.sid or t.el_id = l.sid WHERE t.el_id is NULL Таблица contacts id,sid,type,company_id //Если company_id не null, значит у клиента есть компания. type это клиент или компания Таблица link_contacts_leads id,lead_id,contact_id Таблица leads id Таблица tasks id, el_id //el_id это id контакта или сделки