在sql需要帮助........... [英] need help in sql...........

查看:47
本文介绍了在sql需要帮助...........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我有2个SQL查询,如: -





1)从table1中选择courseid,sem,句号

输出: -



101--1--3




2)选择courseid,sem,句号来自table2

输出: -



101--1--3

102--3--5



现在我需要一个查询,将table2与table1进行比较,并告诉我输出中的列是相同的..这意味着(100--1--3)。我怎么能这样做..

解决方案

两个表上的内部联接将产生你需要的东西,例如:

 选择 t1.courseid,t1.sem,t1.period 
来自 table1 t1
inner join table2 t2 on t1.courseid = t2.courseid t1.sem = t2.sem t1.period = t2.period





有关联接的更多信息,请参阅此CP文章加入SQL Server的类型 [ ^ ]


如果只想使用不同的结果

 选择 courseid,sem,period 
来自 table1
INTERSECT
选择 courseid,sem,period
来自 table2


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..

解决方案

An Inner Join on both tables will produce what you need e.g.

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[^]


if you want only distinct results use

select courseid, sem,period
from table1 
INTERSECT
select courseid, sem,period 
from table2


这篇关于在sql需要帮助...........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆