Click here to Skip to main content
15,038,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frnds,
i have 2 tables in tb1 it has many columns on that i want to select year,batch and want to join on tb2 in both the table has rollno. year and batch should match according to the rollno in tb2 like already in tb1 plz help i had tried this but its not working
SQL
select year, batch from tb1 left join tb2 on tb1.rollno = tb2.rollno;
Posted
Updated 24-Nov-13 2:58am
v3
Comments
Kornfeld Eliyahu Peter 24-Nov-13 8:44am
   
What's your problem...
Arun-23 24-Nov-13 9:02am
   
Not unique table/alias -- tb1 like this error

want to select year,batch from tb1 and want to join on tb2 in both the table it has rollno. year and batch should match according to the rollno in tb2 example in tb1 1,2,3,4 is rollno and in tb2 2,4 is rollno so corresponding year and batch should join for 2 and 4 rollno only in tb2 i hope u got..
Peter Leow 24-Nov-13 8:57am
   
Do you mean to retrieve year and batch from table 1 whereever the rollno in table 1 has a match with rollno in table2?
Arun-23 24-Nov-13 9:04am
   
yeah..
want to select year,batch from tb1 and want to join on tb2 in both the table it has rollno. year and batch should match according to the rollno in tb2 example in tb1 1,2,3,4 is rollno and in tb2 2,4 is rollno so corresponding year and batch should join for 2 and 4 rollno only in tb2 i hope u got.
CHill60 24-Nov-13 11:23am
   
Did you even look at my amended solution on your other post?
enhzflep 24-Nov-13 9:29am
   
Please, don't double post. You already posted this question 19 hours before you posted it again here. ( join of 2columns from tb1 to another table tb2)

1 solution

You should use SQL INNER JOIN that returns all rows from multiple tables where the join condition is met.

try this:

SELECT year, batch FROM tb1 INNER JOIN tb2 ON tb1.rollno=tb2.rollno
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900