mysql query problem

1

I'm having a problem while doing a mysql query. I want to select the id and name of all the presents, except those that are already in the reservation table.

SELECT DISTINCT
    tb_presentes.id_presente AS value_id,
    tb_presentes.nome AS label
FROM
    tb_presentes
INNER JOIN
    tb_reserva
ON
    tb_presentes.id_presente <> tb_reserva.id_presente
WHERE
    tb_presentes.id_cat_presente = 2
ORDER BY
    value_id
    
asked by anonymous 26.01.2018 / 16:40

1 answer

0

Use NOT IN for search for values that are not listed in the parameters

NOT IN (valor1, Valor2...Valores)

And fill in this list with the data in your Reservation table ("where ID NOT IN Reservation").

It would look like this

SELECT DISTINCT
    tb_presentes.id_presente AS value_id,
    tb_presentes.nome AS label
FROM
    tb_presentes
WHERE
    tb_presentes.id_presente NOT IN (select tb_reserva.id_presente from tb_reserva)
AND
    tb_presentes.id_cat_presente = 2
ORDER BY
    value_id
    
26.01.2018 / 16:46