Reputation: 8991
I have two tables: jobs
and applications
.
jobs
has columns including id
(the key) and user_id
(the ID of the user who created the row).
applications
has columns including job_id
(the ID of the job which the application correlates to).
The query I'm trying to construct will perform the following:
jobs
table that has a specific user_id
applications
table whose job_id
correlates to the id
s returned in the previous searche.g.
jobs
table
id user_id ...>
1 1 ...
2 3 ...
3 1 ...
applications
table
id job_id ...>
1 3 ...
2 1 ...
3 2 ...
If I run the query where user_id
=1, it should return rows 1 and 2 from the applications
table as they correlate to the jobs where user_id
=1.
How can this be accomplished?
Upvotes: 0
Views: 111
Reputation: 538
You can just join these two tables to make one "bigger table" with all of your data. You will join them on common column, in your case its Id = job_id.
The query will look like this :
select a.*
from applications a
join jobs j on a.job_id = j.id
where j.user_id = '1'
Upvotes: 0
Reputation: 1910
select app.* from applications app, jobs j
where j.id = app.job_id
and j.user_id = '1'
Using join.
Upvotes: 2