All we need is an easy explanation of the problem, so here it is.
I have two individual queries, which I have to join them into single query.
1st query:
I have a parameter called name in a request. When I give that name, it should determine its id. Example: If I give VS-ABC in a request it should determine it’s id=1.
stu_details table
[{id:1,name:"VS-ABC"]} -- sample input record to refer
select * from stu_details where name="VS-ABC"
2nd query:
select * from PR
where pr_id in (select pr_id from PRS where id =1)
Here id =1 and I am giving it manually, but I wanted these queries to run in a single shot and dynamically. Whenever I pass a request "name" parameter then it should determine that id and pass in the second query inside IN query.
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
SELECT [DISTINCT] pr.*
FROM pr
JOIN prs ON pr.pr_id = prs.pr_id
JOIN stu_details ON stu_details.id = prs.id
WHERE stu_details.name = 'VS-ABC';
Whether DISTINCT is needed or not depends on the data.
PS. Do not use double quote chars "
for literals quoting, you must use single quote chars '
for this purposes.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0