加入sqlserver 2005 [英] join in sqlserver 2005

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

问题描述


我有两个表都具有相同的字段,一个有两个字段,分别称为价格和总计
我要同时加入两个表,并希望从第一个表中获取某些字段,并从第二个表中获取价格和总计,所以我有两行用于特定顺序,然后我的结果显示4行(两者均为2 + 2),但我只希望有2行

解决方案

第一个表table1
OrderId,
OrderName,
日期

第二表table2
OrderId,
价格,
总计

table1 t1

选择订单编号,价格,总计
内部加入 table2 t2在t1.Orderid = t2.OrderId 



现在,这只会给我3列.您可以像这样写任何想要的字段


hi
i have two table both have same fields one have two fields different called price and total
i am join both tables and want to fetch some fields from first table and price and total from second table let i have two rows for a particular order then my result shows 4 rows (2+2 from both) but i want only two rows

解决方案

First table table1
OrderId,
OrderName,
Date

Second table table2
OrderId,
Price,
Total

Select OrderId, price, total from table1 t1
inner join table2 t2 on t1.Orderid=t2.OrderId



Now this will give me only 3 columns. you can write whatever fields you want like this


这篇关于加入sqlserver 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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