Problem in mysql query

Asked

Viewed 26 times

1

I’m having a problem doing a mysql query. I want to select the id and name of everyone present, except those already in the booking 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

1 answer

0


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

NOT IN (valor1, Valor2...Valores)

And fill out this list with your Booking table details ("where NOT IN Booking ID").

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
  • 1

    Man... thanks bro. Thank you so much for your help!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.