I would like to formulate a query that returns the vin, customer_id and model_id where the same customer_id has multiple records that have a model_id of “toyota” from the CAR table. The vin in the primary key and unique. Any ideas? I’m using Oracle 10g.
CAR Table:
vin varchar (primary key)
customer_id varchar
model_id varchar
Data:
vin customer_id model_id
------------------------------------
222313XYZ, cust1234, toyota
123232SSS, cust1234, toyota
111111ERE, cust1111, bmw
999999LKO, cust1224, bmw
SQL Fiddle
Oracle 11g R2 Schema Setup:
Query 1: in case you want to see all models whose owners also own more than one toyota
Results:
Query 2: in case you want to see only toyotas whose owners own more than one of them:
Results: