Select between 2 tables

Asked

Viewed 80 times

2

Based on the tables below and passing to 'dataInicio' and 'dataFim', would it be possible with only one Select select from the Vehicle Table only vehicles that are not in the Reserve Table? I’m studying Inner Join, but I have no idea if that’s possible.

Tabela Veiculo
--------------
idVeiculo
nomeVeiculo


Tabela Reserva
--------------
idVeiculo
dataInicio
dataFim

1 answer

2


The first thing to do is create a key for the relationship between the 2 tables, after that, would be like this for example:

SELECT v.nomeVeiculo FROM VEICULO v
INNER JOIN RESERVA r on v.id not in r.veiculo_id;
  • Thank you. Follow the final logic. SELECT * FROM vehicle WHERE idVeiculo NOT IN (SELECT veiculo_idVeiculo FROM reservas WHERE dataIni BETWEEN '". $dataini." ' AND '". $datafim." ' OR dataFim BETWEEN '". $dataini." ' AND '". $datafim."');

Browser other questions tagged

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