Help with request (mysql).

Table of applications, Table of photos on applications.

I need to display a list of numbers of those applications that are not in the table with photos. (Ie, I need a list of applications that do not have a photo).

I do something like:

SELECT num FROM customerequipment WHERE num NOT IN (SELECT OrderID from attaches). 

But returns null

  • five
    Since it returns null, then the only entries for which there is nothing in the attaches table contain the num field value null. This I mean, the request looks absolutely working, so it's about the data and not about the request - Mike
  • The only thing that can be is that you have mixed up the columns. Do you have exactly customerequipment.num and attaches.OrderID contain the same thing? - German Borisov
  • Yes, they contain the same thing - Eser
  • I did it through a union like it works: SELECT num FROM customerequipment LEFT JOIN attaches ON (customerequipment.num = attaches.OrderID) WHERE attaches.OrderID IS NULL AND customerequipment.StateID! = 1 - Eser
  • And what is the structure of the tables? num in the customerequipment table is the OrderID in the attaches table? Accidentally not confused fields? - koshe

1 answer 1

 SELECT num FROM customerequipment LEFT JOIN attaches ON (customerequipment.num=attaches.OrderID) WHERE attaches.OrderID IS NULL AND customerequipment.StateID!=1