Ok, I’ve been searching for two days and have not found anything. I think this is a simple problem, I’m just not able to wrap my head around it for some reason.
Say you have two tables.
Cars
CarID
CarModel
CarTypes
CarTypeID
CarID
TypeOfCar
Example data for Cars:
CarID CarModel
A Pinto
B Corvette
C Ferrari
Example data for CarTypes:
CarTypeID CarID TypeOfCar
1 A ChickMagnet
2 A FourDoor
3 A GasGuzzler
4 B SportsCar
5 B TwoDoor
6 B GasGuzzler
7 C GasGuzzler
8 C TwoDoor
9 C ChickMagnet
Car and CarType have a 1 to many relationship (A car can be many different types). I cannot wrap my head around the sql that would be required to show all cars that are a “ChickMagnet” AND a “GAS Guzzler”
Result Set Desired:
CarID CarModel
A Pinto
C Ferrari
Any help would be greatly appreciated. I’m using SQL Server. I can do it using Like and Text searches but would like to avoid that.
1 Answer