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.

1 Answer 1

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.

  • Now in where condition I am giving actual value, but I have to get input "name" column and assign it to name, How I can do that? Jun 8 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.