sql - How to get the right output from this query -
im creating sql query outputs licenseplate dbo.car when there stock of car. means have under dbo.sell , dbo.rent make sure car not sold or under rental.
i need have output following:
licenseplateno -------------- sgk5556a
but output blank. have following statement:
select licenseplateno car inner join cartransaction on car.chassisno = cartransaction.chassisno inner join sell on cartransaction.transactionid = sell.transactionid inner join rent on cartransaction.transactionid = rent.transactionid car.make = 'toyota' , sell.transactionid in (select transactionid sell) , rent.transactionid in (select transactionid rent)
i cant seem right query. moment when query works when did not specify query dbo.rent. need validate whether if car available through rental history
the inner joins not needed , car never in sell , rent @ same time, query can written as:
select licenseplateno car inner join cartransaction on car.chassisno = cartransaction.chassisno car.make = 'toyota' , cartransaction.transactionid not in (select transactionid sell) , cartransaction.transactionid not in (select transactionid rent) ;
Comments
Post a Comment