I have two queries that I want to run against a certain type of product, to check whether a product exists with certain specifications.
Therefore I first want to check if a product contains a type=A
, and if so check again if it either contains type=B or C
.
How can I combine this both into a single query?
table cars:
id;product;type
0;car;A
1;car;B
2;car;C
Current two-step SQL:
SELECT 1 FROM cars where product = 'car' and type = 'A';
if so:
SELECT 1 FROM cars where product = 'car' AND (type = 'B' OR type = 'C');
2
Answers
It sounds like you need to combine them with exists, such as
Assuming
product
is "grouping" field in your table you might need something like this.