Goarge Go Goarge Go - 6 months ago 8
SQL Question

get results from mysql table while matching results from another

I am trying to get result if id match in both tables, currently i have 2 table with structure below

1- checkin_bonus TABLE

| user_id |

| 2 |
| 5 |
| 1 |


2- user_pages TABLE

| user_id | score |

| 2 | 100 |
| 3 | 300 |
| 6 | 600 |


Desire Results: if user_id of table checkin_bonus match any user_pages user_id return result in example case user_id & score = 100 should displyed
i am doing something like this but no success

My app is MVC Based

Model.php

// Checkin Pages
public function checkinpagesL()
{
return $this->db->select('SELECT user_id FROM checkin_bonus AS c
AND user_id FROM user_pages AS u JOIN WHERE c.user_id = u.users_id ');


}



View.php
<?php
foreach($this->checkinpagesL as $key => $value) {?>
<tbody>
<tr>
<td><?php echo $value['user_id']?></td>
<td><?php echo $value['score']?></td>
</tr>
</tbody>
<?php }?>
</table>


It will help me alot.

Answer

Actually whats your field name?? Is it user_id or users_id?

if it is user_id, then please replace join on clause with u.user_id and try.

SELECT u.user_id as id FROM checkin_bonus AS c 
JOIN user_pages AS u ON c.user_id = u.user_id 
where c.user_id > 18 ORDER BY c.user_id DESC