0

I have a simple and silly doubt in sql. I have to write down a query like the one below. Here, id is not unique. But when i do the following query i get unique values as output. How do i get multiple values?

select name from students_table where id in (select id from students_id);

Ex : Lets say students_table has name   id
                                 -----  ---
                                 john    1
                                 jack    2

     And students_id table has   id    
                                 ---
                                  1
                                  1
                                  1
                                  2
                                  ...

If i write the query in the above way i get name
                                            ----
                                            john
                                            jack

Instead i want my output as name
                            ----
                            john
                            john
                            john
                            jack
1
  • check my answer below. i'm pretty sure it worked! :D Commented Sep 6, 2012 at 22:42

3 Answers 3

2
select st.name from students_id si
join students_table st on st.id = si.id;
Sign up to request clarification or add additional context in comments.

Comments

1

You need to JOIN both tables. Try this,

SELECT  a.Name
FROM    student_table a
        INNER JOIN student_ID b
             on a.ID = b.ID

This is what you are looking for.

Comments

0

You want to do a join:

select t1.name from students_table t1 inner join students_id t2 on t1.id = t2.id

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.