I’ve been playing around with a few SQL queries trying to get the column name when the field from the row is equal to 1.
My table looks like this:
user | col 1 | col 2 | col 3 | col 4 |
user1 | 1 | 1 | 0 | 1 |
user2 | 0 | 1 | 1 | 1 |
user3 | 1 | 0 | 0 | 1 |
I’m trying to get each column name to display for when each value is equal to 1.
SELECT ColNames
FROM table
WHERE user1 = 1
As above, you need three tables. One for users, one for items, and one that joins the two. Here’s the structure and queries that I use for a similar function, maintaining user defined mailing lists:
And the query that pulls up members from a particular list:
Hope that helps.