The problem: In a car database there is a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice. Use a subquery along with IN to list all the Model Names with a Sticker Price greater than $30000
I was able to solve the problem using:
SELECT ModelName FROM MODEL
WHERE ModelID IN (SELECT ModelID FROM CAR WHERE stickerPrice >30000);
however, I am trying to subquery the "MODEL" table instead to display the "model name" and "sticker price" using the "IN" keyword but I am getting some errors. I tried:
SELECT ModelName, stickerPrice FROM car
WHERE stickerPrice >30000
AND ModelID IN(SELECT ModelID From Model);
but I got and error because "modelname" is a field on the Model table. I also tried alias:
SELECT M.ModelName, stickerPrice FROM car
WHERE stickerPrice >30000
AND ModelID IN(SELECT ModelID From Model) AS M;
but I get a syntax error because of the "AS" keyword.
I just not sure why doing it the other way will not work as expected.