sql-workbench find record that is not repeated in two tables

0

Good morning everyone ... Let's see who can help me with this simple query ... I have a database formula 1, in it there are two tables, one is cars and the other participation, the participation table has the key (codeCoche) foreign cars that participated in races in certain years. What they ask me is basically that they make a query that shows only the cars that did not participate in a race. I have done this but it does not run ..

SELECT codiCotxe
  FROM formula1.Cotxe
 WHERE not in(SELECT codiCotxe from formula1.Participació);

These are the car table

And the participation table

Gracuas in advance

    
asked by Carlos 01.11.2017 в 16:30
source

1 answer

0

You lack the name of the column before NOT IN :

WHERE codiCotxe NOT IN(...

Alternatively, you can use NOT EXISTS , which can sometimes result in better performance for this type of query:

SELECT c.codiCotxe
  FROM formula1.Cotxe c
 WHERE NOT EXISTS (SELECT NULL
                     FROM formula1.Participació p
                    WHERE p.codiCotxe = c.codiCotxe)
    
answered by 01.11.2017 / 16:34
source