php - how to join two tables using eloquent or query builder -
i have query lists topics 2 users have in common.
$subcommon= subjectuser::selectraw('topic_id, count(topic_id) aggregate') ->wherein('user_id', [4, 2])->groupby('topic_id') ->having('aggregate','>',1)->get();
for example query result table below be
{"topic_id":3,"aggregate":1}
tableone
id|user_id|topic_id 1|2 |3 2|4 |3 3|5 |1
i have table(tabletwo) has topic_id join query result of row 2 second table. how go doing this?
tabletwo
id|group_id|topic_id 1|6 |2 2|7 |3 3|7 |1
db::table('tableone')->join('tabletwo', function($join) { $join->on(tableone.topic_id, '=', tabletwo.topic_id); })->get();
Comments
Post a Comment