1

I am searching for the best way to do that: I have table with columns ID, network1, network2....30. the value in the column is true or false. I want to get string with network numbers for all row when the value is true.

like this:

"5,7,8"

when the values in network5 and network7 and network8 are true and the others is false.

can you please advise?

2
  • Have you considered using MySQL's SET datatype instead? Commented Jun 7, 2016 at 10:17
  • Or rather a normalisation (store id - network pairs in their own record) Commented Jun 7, 2016 at 10:30

1 Answer 1

2

You can try using multiple IF's combined with CONCAT()

SELECT t.id,
       concat(IF(t.network1 = 'TRUE','1,',''),
              IF(t.network2 = 'TRUE','2,',''),
              IF(t.network3 = 'TRUE','3,',''),
              IF(t.network4 = 'TRUE','4,',''),
              .....
FROM YourTable t
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.