I am doing fairly large SQL, so I apologize that can not provides a larger example of my tables.
SELECT
customer_id,
agreement_id,
if( 'network' IN ( GROUP_CONCAT( DISTINCT services.service_code
SEPARATOR ',' ) ),
'Yes','No') as networkservice
FROM customers
INNER JOIN agreement USING(customer_id)
INNER JOIN services USING(agreement_id)
GROUP BY customer_id
A customer may have an agreement, and the agreement may have many services. I am trying to find out if the โnetworkโ is one of the services in this agreement.
Since GROUP_CONCAT returns a comma separated list, it feels perfect for my business. But I can't get it to work, and my ideas are running out.
If there is only one service, and this service is a "network", it returns "yes", but if there is more than one, then "No".
(INT) service_id, , INT Im look for . INT, "network" , No.
:
if( 'network' IN ( CAST(GROUP_CONCAT( DISTINCT services.service_code
SEPARATOR ' ' ) AS CHAR) ),
'Yes','No')
if( 'network' IN ( concat('\'',
GROUP_CONCAT(DISTINCT services.service_code
SEPARATOR '\', \'' ),
'\'') ), 'Yes','No')
, .
.