0

I have a table t1:

c1 c2 
1  a
2  b
3  a

table t2:

c3  c4
4    1
5    2
6    3

I am writing a procedure:

select c1 from t1 where c2 = 'a'; 

which will give multiple outputs. Use that output (1,3)

select c3 from t2 where c4 = 1,

select c3 from t2 where c4 = 3 -- out put of first query;

How do I implement it ? Should i use any loops? If so, how do I loop or how do I write a procedure which returns the result of it?

1
  • That's really very basic SQL. Before writing procedures, you should learn the basics. Any SQL tutorial, even the worst of them, explains joins. Commented Nov 14, 2019 at 7:15

4 Answers 4

1

you can use join

select c1,c3 from t1 
inner join t2 on t1.c1=t2.c4
where c2='a' 
Sign up to request clarification or add additional context in comments.

Comments

1

You might have to work more on it but this is how i think this can be implemented.Inside the SP create a table data type where you can insert the multiple values fetched and then you can pass these values to another SP as a table value parameters where you can do the rest of the operations.

Comments

1

You can use in

select c3 from t2 where c4 in
(select c1 from t1 where c2 = 'a')

Comments

0
select c1,c3 from t1,t2
where t1.c1=t2.c4 and  c2='a' 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.