Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

christopher's avatar

How to make such a simple SQL query

I am passing a context_id, let's say 12345 to a MYSQL query.

I have two tables.

Table A: contains column user_id & context_id. Table B: user_id, name etc.

Now i need to search in Table A for context_id 12345 which i passed to get the user_id from Table A. With this user_id i want to get every record from Table B which is equal to user_id.

How would i make such a call as a blank SQL query without Eloquent?

0 likes
2 replies
Sinnbeck's avatar

Assuming that it is user_id on both tables

SELECT b.* from table_a as a
Join table_b as b on a.user_id = b.user_id
where a.context_id = 12345

Please or to participate in this conversation.