I'm trying to do a subquery correlated, but not getting the right answer. I'm tried query 'suv' vehicles and inside this suv vehicles I would like vehicles made by BMW, but I'm getting all vehicles that are SUV. What should i do?
-- create a table
CREATE TABLE Cars (
id INTEGER PRIMARY KEY,
CarName varchar(50),
vehicle_type varchar(50),
Automaker varchar(50),
Price INTEGER
);
-- insert some values
INSERT INTO Cars VALUES
(1, 'BMW X6', 'SUV','BMW', 108200),
(2, 'BMW X6', 'SUV','BMW',88200),
(3,'Grand Cherokee','SUV','JEEP' ,21678),
(4,'Grand Cherokee','SUV','JEEP' , 24518),
(5,'Grand Cherokee','SUV','JEEP' , 27548),
(6,'BMW 320','Sedan','BMW' , 54518),
(7,'AUDI A8','Sedan','AUDI' , 64518);
SELECT * FROM Cars WHERE vehicle_type = (SELECT vehicle_type from Cars WHERE Automaker = 'BMW');