Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir, i have 2 sql query like:-


1) select courseid,sem,period from table1
Output :-

101--1--3


2) select courseid,sem,period from table2
output:-

101--1--3
102--3--5

now i need a query that compare table2 with table1 and give me that column in with output are same.. it means (100--1--3). how can i do it..
Posted
Comments
CHill60 16-Jan-15 6:51am    
Have you tried anything?
Er. Puneet Goel 16-Jan-15 6:52am    
What type of compare you want ? Can you give some better example. As table 2 has 2 rows and table one has 1.So which type of compare ?
deepakdynamite 16-Jan-15 7:05am    
use Inner join...

An Inner Join on both tables will produce what you need e.g.
SQL
select t1.courseid, t1.sem, t1.period
from table1 t1
inner join table2 t2 on t1.courseid = t2.courseid and t1.sem = t2.sem and t1.period=t2.period


For further information about Joins see this CP article Types of Join in SQL Server[^]
 
Share this answer
 
if you want only distinct results use
SQL
select courseid, sem,period
from table1 
INTERSECT
select courseid, sem,period 
from table2
 
Share this answer
 
v2

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