How to query to get only show where on the other table has a relation id of a field. Example My explain table is:
In Table Users
+--------+------------+
| id | username |
+--------+------------+
| 1 |zuck |
| 2 |renold |
| 3 |arby |
| | |
In Table Class
+--------+------------+------------+
| id | user_id | class_name |
+--------+------------+------------+
| 1 | 1 | ABC |
| 2 | 1 | EFG |
| 3 | 1 | HIJ |
| 4 | 2 | KLM |
| 5 | 2 | NOP |
And I want to get result as below:
Array
(
[0] => Array
(
[id] => 1
[username] => zuck
[class] => Array
(
[0] => array(
[id] => 1
[class_name] => ABC
)
[1] => array(
[id] => 2
[class_name] => EFG
)
[2] => array(
[id] => 3
[class_name] => HIJ
)
)
)
[1] => Array
(
[id] => 2
[username] => renold
[class] => Array
(
[0] => array(
[id] => 4
[class_name] => KLM
)
[1] => array(
[id] => 5
[class_name] => NOP
)
)
)
)
So username arby not show because he dont have a relation in table class. In table class there is not user_id 3. So will show only user zuck and renold. I try with query left join, outer join, inner join, but not success :-(
Thanks for help.