Select in items that have not been inserted

Asked

Viewed 27 times

-1

Next, I have table entries in case list of requests to rent a dvd The Tabelab will be inserted which dvd I will rent, so I need to select the list of dvds that were not rented in Table or just bring me the items that are not within Table.

Table Tabub

Tabelab will receive the data from Tabelaa I need to select Table items that are not yet within Table.

  • You can detail a little the structure of the tables?

  • Next, I have items from the table In case of requests to rent a dvd The Table will be inserted which dvd I will rent, so I need to select the list of dvds that were not rented in the Table or just bring me the items that are not within the Table

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 this one working on Sql Fiddle

  • SELECT se.codemprestimo, se.dataemprestimo, se.horaemprestimo, se.codigo_socio_solicitou_emprestimo, se.dvd_codigo, se.socio_codigo, e.solicitacaoemprestimo_socio_codigo
FROM solicitacaoemprestimo se, emprestados e
WHERE se.socio_codigo = ? AND NOT e.solicitacaoemprestimo_socio_codigo = se.socio_codigo ORDER BY dataemprestimo ASC, horaemprestimo ASC ;

  • how do you put edited... damn... hahahhahahaha

Browser other questions tagged

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