Please review the select statement:
SELECT
fc.flavorid,
fc.flavorname,
CASE
WHEN sa.flavorid IS NULL THEN 'No'
ELSE 'Yes' END ) IsEaten
CASE
WHEN t.tempid IS NULL THEN 'No'
ELSE 'Yes' END ) IsWarm
FROM [poptart] p
LEFT JOIN [diet] d ON d.Active = 1
LEFT JOIN [toaster] ts ON p.poptartid = ts.poptartid AND d.dietname = ts.dietname
LEFT JOIN [flavor] fl ON fl.poptartid = ts.poptartid
LEFT JOIN [flavorcolor] fc ON fc.flavorid = fl.flavorid
LEFT OUTER JOIN [stomach] sa ON sa.flavorid = fc.flavorid
LEFT JOIN [poptart] p2 ON ts.poptartid = p2.poptartid
LEFT JOIN [temp] t ON t.tempid = p2.tempid AND t.Active = 1
GROUP BY fc.flavorid,fc.flavorname,sa.flavorid,t.tempid
ORDER By fc.flavorname
As you can see below, this returns one for each IsWarm value for the โberryโ. I want only certain fragrance names to appear on this list, but the IsWarm field has become a problem because it can be Yes or No, and I want to show only Yes if Yes is available, and not โYesโ and โNoโ, pull out duplicate flavors like โberryโ:
flavorid | flavorname | IsEaten | IsWarm
123 | berry | No | Yes
123 | berry | No | No
234 | fudge | Yes | No
235 | honey | No | No
How to force this operator to return only this.?
flavorid | flavorname | IsEaten | IsWarm
123 | berry | No | Yes
234 | fudge | Yes | No
235 | honey | No | No
Any suggestions?
source
share