Hey all! I am currently trying to get some data using the following query:
Code:
SELECT PZ.ID, PZ.CUST, (SELECT TP.NAME FROM TOPPING TP WHERE TP.TYPE = 'meat' AND TP.ID = PZ.ID) AS TOP FROM PIZZA PZ
If my tables look like this:
Code:
PIZZA:
[ID: 0, CUST: 'dave']
[ID: 1, CUST: 'bob']
[ID: 2, CUST: 'tracy']
TOPPING:
[ID: 0, NAME: 'pep', TYPE: 'meat']
[ID: 3, NAME: 'mushroom', TYPE: 'veggie']
[ID: 1, NAME: 'mozzarella', TYPE: 'cheese']
[ID: 1, NAME: 'sausage', TYPE: 'meat']
[ID: 0, NAME: 'mozzarella', TYPE: 'cheese']
the above query would return me the following information:
Code:
[ID: 0, CUST: 'dave', TOP: 'pep']
[ID: 1, CUST: 'bob', TOP: 'sausage']
[ID: 2, CUST: 'tracy', TOP: '']
Now here is my question! I want to be able to search over the results of this query by possibly using a WHERE clause at the end that would do something like this:
Code:
SELECT PZ.ID, PZ.CUST, (SELECT TP.NAME FROM TOPPING TP WHERE TP.TYPE = 'meat' AND TP.ID = PZ.ID) AS TOP FROM PIZZA PZ WHERE TOP LIKE '%sau%'
To get only Bob's pizza:
Code:
[ID: 1, CUST: 'bob', TOP: 'sausage']
Is this possible? Am I missing an alias somewhere possibly? Maybe nest yet another SELECT around the query and do the WHERE there? Any thoughts would be much appreciated! Thank you so much!
Bookmarks