Not Equals in the Where clause

0

I have the following tables

create table Puesto
(
    id_puesto int identity(1,1) primary key not null,
    piso int,
    cantidad_sillas int,
    frente_ventana bit,
    cantidad_computadoras int,
    cantidad_sillas_adicionales int,
    acceso_sala_reuniones bit
)

create table Alquiler
(
    id_alquiler int identity(1,1) primary key not null,
    id_puesto int,
    foreign key (id_puesto) references Puesto (id_puesto),
    dni_cliente int,
    foreign key (dni_cliente) references Cliente (dni),
    precio money,
    adicion_ventana money,
    adicion_computadoras money,
    adicion_acceso_tiempolibre money,
    adiccion_sillas money
)

And I need to get all those positions that are not for rent. For the following I deduce that I do not have to show all those Posts whose set_id is equal to the set_id of my Rent table. I have the following code but it does not give me the desired results.

SELECT Puesto.piso, Puesto.cantidad_sillas, Puesto.frente_ventana, Puesto.id_puesto, Alquiler.id_puesto
FROM Puesto, Alquiler
WHERE Puesto.id_puesto != Alquiler.id_puesto

I have tried using < > instead of ! = but the results are the same.

    
asked by Lucas. D 28.10.2017 в 00:09
source

1 answer

1

Well, if you try to show all the positions that are not for rent, you can do a Left OUTER Join and show those that your ID is null:

SELECT Puesto.piso, Puesto.cantidad_sillas, Puesto.frente_ventana, Puesto.id_puesto, Alquiler.id_puesto
FROM Puesto LEFT OUTER JOIN Alquiler ON Puesto.id_puesto = Alquiler.id_puesto 
WHERE Alquiler.id_alquiler IS NULL
    
answered by 28.10.2017 / 00:23
source