Query using Inner Join and left Join data together

Asked

Viewed 32 times

1

I’m making a system with php and mysql to control the input and output of vehicles in a company, so there are two tables, one to record the output information and the other to save the return information. Within the system I am doing a part of research to show the completed records (vehicles that have left but returned) and the open records (vehicles that have left but not yet returned) I know that the completed records I can represent through the Inner Join gathering data from the output table and the return table, but the open records should be only the output data(lines) that are not used in the function Inner Join, would be more or less (OUTPUT DATA) - (OUTPUT DATA USED IN INNER JOIN) Could anyone help me on how I can do this please? OBS. The vehicles are fixed so they are always the same that keep changing between completed and open records.

1 answer

0

Make a LEFT Join of the table out with the entry table as well, the records that come with NULL in the entry table, it is because the vehicle has not returned yet.

select s.veiculo_id, e.veiculo_id from saida s LEFT join entrada e on e.veiculo_id = s.veiculo_id

output:
veiculo_id veiculo_id
1          1
2          NULL

Browser other questions tagged

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