询问两张桌子 [英] Enquiry on two tables

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

问题描述

大家好,我需要查询哪个连接两个表。我该怎么做?我有这些表

手机品牌
PhoneID PhoneID
PhoneName BrandName

如何将我的PhoneId插入品牌表

解决方案

在内部联接的帮助下,您可以这样做很简单,例如查询

 选择 p.Phone,p.PhoneName,b.Brand,b.BrnadName  from 电话p(第一个表名)内部加入品牌(第二名表)b on p.PhoneID = b.PhoneID 





更多链接显示在下方信息如何使用Inner Join。

试试这个链接

http://www.tutorialspoint.com/sql/sql-inner-joins.htm [ ^ ]


先生,我想你应该反之亦然,如将 BranchId 字段添加到电话表,这将使其更合适,因为在分支机构中可以有50部电话但在一部电话中可以只有一个分支。


加入

 选择 p.PhoneID,p.PhoneName,b.BrandName 来自电话p 内部 加入品牌b   p.phoneid = b.brandid 





insert

  insert  进入品牌(phoneid,brandname)'  phoneid'' 您的品牌名称


Hi guys, I need to query which joins two tables. How should I do this? I have these tables

Phone            Brand
PhoneID          PhoneID
PhoneName        BrandName

How do I get my PhoneId to be inserted in the Brand Table

解决方案

It's simple you can do this with the help of Inner Join, like this Query

select p.Phone,p.PhoneName,b.Brand,b.BrnadName from Phone p(first Table Name) inner join Brand(Second Table Name) b on p.PhoneID=b.PhoneID



More link are show below a complete information how can used the Inner Join.
try this link
http://www.tutorialspoint.com/sql/sql-inner-joins.htm[^]


sir, i think you should do it vice-versa like take BranchId field should be added to Phone table that will make it more appropriate because in a branch there can be 50 phones but in one phone there can be only 1 branch.


Joining

select p.PhoneID ,p.PhoneName ,b.BrandName from Phone p inner join brand b on p.phoneid = b.brandid



for insert

insert into brand ( phoneid , brandname) values ( 'phoneid','your brand name')


这篇关于询问两张桌子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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