'How to SELECT value of the column WHEN EXIST
I try to find a way to retrieve the text of a specific column when existing otherwise return 'NONE', here my query :
SELECT
t_operation.*,
CASE WHEN EXISTS (SELECT OperationID FROM t_operationtag
WHERE t_operationtag.ElementID = t_operation.OperationID
and t_operationtag.Property = "Category"
and t_operation.Name LIKE CONCAT("%", "class", "%"))
THEN 'FOUND'
ELSE 'NONE'
END AS TagValue
FROM t_operation
Instead of 'FOUND' I would like to retrieve the value, like following (but this didn't work):
SELECT
t_operation.*,
CASE WHEN EXISTS (SELECT OperationID FROM t_operationtag
WHERE t_operationtag.ElementID = t_operation.OperationID
and t_operationtag.Property = "Category"
and t_operation.Name LIKE CONCAT("%", "class", "%"))
THEN t_operationtag.VALUE
ELSE 'NONE'
END AS NewFiled
FROM t_operation
I opened an dbfiddle to try the query : https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=ba10216a0979f0cc8adc16b4a867a05b
Thanks Yan
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
