Select on items that were not inserted

-1

Next, I have items from theA table in the case list of requests to rent a dvd The TableB will be inserted which dvd I will rent, so I need to select the list of dvds that were not rented in TableA or just bring me the items that are not inside TableB.

TableA Table B

TableB will receive the data from TableA I need to select the items in TableA that are not yet within TableB.

    
asked by anonymous 04.06.2015 / 19:17

1 answer

0

Simulating your case with the following table structures:

CREATE TABLE Dvds('id' int, 'nome' varchar(29));

CREATE TABLE DvdsAlugados('id_dvd' int, 'id_usuario' int);

You can select which ones are not rented in the following ways:

select dvd.* from Dvds dvd
left join DvdsAlugados a on a.id_dvd = dvd.id
where a.id_usuario is null;

Or:

select * from Dvds where id not in(select id_dvd from DvdsAlugados);

You can see the one working on Sql Fiddle

    
04.06.2015 / 19:35