sql server - SQL query for selecting all items except given name and all rows with id of that given name -
i apologize messy title. please consider following tables:
car_model : car_model_id, car_name car_inventory : car_model_id, car_location_name,
the user pass in car_location_name, , list of car_name excluding rows given car_location_name, , cars id of car_location_name.
let me explain further.
for join such, let's assume user passes in "germany." list excluding row #2 , #6, have car_location_name of "germany." exclude rows car_id of row germany. (in case car_id of 2 , 6, row car_id of 2 or 6 should eliminated.) in case, since germany has car_id of 2, rid of row car_location_name of "canada", since has car_id of 2.
the result should be:
what sql query (can sql server specific) can use achieve this?
i'm sorry if explanation confusing - please ask questions if having trouble understanding i'm trying say.
simplest join results usual, , eliminate car_model_ids exist in germany;
select cm.car_model_id, ci.car_location_name, cm.car_name car_model cm join car_inventory ci on cm.car_model_id=ci.car_model_id cm.car_model_id not in ( select car_model_id car_inventory car_location_name='germany' )
Comments
Post a Comment