Question: I want to know if a certain ID has a certain function turned on. but the functions are in other table. 

Table 1:

```
userID Name
     1 aaa
     2 bbb
     3 ccc

```

Table 2:

```
functionID useID
         1     1
         2     1
         2     2
         3     2
         1     3
         3     3

```

Table3

```
userID Name function1Enabled function2Enabled function3Enabled
     1 aaa  True             True             False
     2 bbb  False            True             True 
     3 ccc  True             False            True

```

Answer: 
You can try to use `JOIN` with conditional aggregate function

```
create table Table1(
   userID int,
  Name varchar(50)
);

insert into Table1 values (1,'aaa');
insert into Table1 values (2,'bbb');
insert into Table1 values (3,'ccc');

create table Table2(
   functionID int,
  userID int
);

insert into Table2 values (1,1);
insert into Table2 values (2,1);
insert into Table2 values (2,2);
insert into Table2 values (3,2);
insert into Table2 values (1,3);
insert into Table2 values (3,3);

```

**Query 1**:

```
SELECT  t1.userID,
        t1.Name,
        IFNULL(MAX(CASE WHEN t2.functionID = 1 then 'true' end),'false') function1Enabled,
        IFNULL(MAX(CASE WHEN t2.functionID = 2 then 'true' end),'false') function2Enabled,
        IFNULL(MAX(CASE WHEN t2.functionID = 3 then 'true' end),'false') function3Enabled
FROM 
Table1 T1  
LEFT JOIN Table2 t2 ON t2.userID = T1.userID
GROUP BY t1.userID,
        t1.Name

```

**[Results](http://sqlfiddle.com/#!9/53ddef/15/0)**:

```
| userID | Name | function1Enabled | function2Enabled | function3Enabled |
|--------|------|------------------|------------------|------------------|
|      1 |  aaa |             true |             true |            false |
|      2 |  bbb |            false |             true |             true |
|      3 |  ccc |             true |            false |             true |

```
```
SELECT t1.userID, t1.Name
   , CASE WHEN COUNT(CASE WHEN t2.functionID = 1 THEN 1 ELSE NULL END) > 0 THEN 'True' ELSE 'False' END AS function1Enabled
   , CASE WHEN COUNT(CASE WHEN t2.functionID = 2 THEN 1 ELSE NULL END) > 0 THEN 'True' ELSE 'False' END AS function2Enabled
   .... and so on
FROM table1 AS t1
LEFT JOIN table2 AS t2 ON t1.userID = t2.userID
GROUP BY t1.userID, t1.Name
;

```

Notes: 

* Aggregate functions, like COUNT, ignore NULL values.
* `ELSE NULL` is actually not required; it is implied if there is no `ELSE` in a `CASE`
* This could be shortened using `IF()` instead of `CASE`, but CASE is more portable to other RDBMS.
* The `LEFT JOIN` will insure you get all table1 records, even if they have no functions mapped in table2.
* No, there is no special syntax to get the "functionNEnabled" result fields to be dynamically created for each function id value; if you add a new function id, this kind of query will need modified.