Hello. How can I use Select statement inside CASE ...
# suiteql
b
Hello. How can I use Select statement inside CASE WHEN? I tried
Copy code
SELECT tableB.id,
    CASE 
        WHEN (SELECT COUNT(t.id) FROM tableA as t) = 1 THEN 'true'
        ELSE 'false'
    END AS custom
FROM 
    tableB
But it didn't work. It returns this error.
Search error occurred: Invalid or unsupported search
c
I'm curious about your motivations here, but regardless: you should be able to achieve what you're trying to do with a CTE, something like
Copy code
WITH cte AS (
  SELECT COUNT(t.id) AS count
  FROM tableA AS t
)
SELECT
  tableB.id,
  CASE WHEN tableA.count = 1
    THEN 'true'
    ELSE 'false' END
    AS custom
FROM tableB
JOIN cte ON 1=1