如何一次获取两个表数据 [英] how to get two table data at a time

查看:83
本文介绍了如何一次获取两个表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个表

1.注册
ID主键自动递增
经销商名称,
手机,
Dob等.

2.产品
用户ID主键自动递增,
过帐类型(有出售和出租两种选择)
id外键
地址,
城市
价格,位置

RadioButtonList,其中包含两个项目1:卖出2:出租

我希望如果选择了卖出,然后从第一个表中检索经销商名称和移动电话,并从第二个表中检索地址,城市,价格和地区,并通过选择的单选按钮满足条件.

请帮帮我吗?

There are two table

1.registration
Id primary key auto increment
dealer name,
mobile,
dob etc.

2.product
userid primary key auto increment,
Posting type(which have two option sell and rent)
id foreign key
address,
city
price,locality

and a RadioButtonList with two items 1:Sell 2:Rent

I want that if sell is selected then retrieve dealer name and mobile from first table and address, city, price and locality from second table where condition is met with selected radio button.

Please help me?

推荐答案

使用左外部联接,其中第一个表将是注册项,第二个表将是产品,

内部联接出现问题,如果在第二个表中找不到匹配的记录,则不会显示数据,

了解有关联接的更多信息:

http://blog.sqlauthority.com/2009 /04/13/sql-server-introduction-to-joins-basic-of-joins/ [
Use the Left outer join, where first table will be registration and second would be product,

problem with inner join if there is no matching record found in the second table then data will not be displayed,

read more about joins:

http://blog.sqlauthority.com/2009/04/13/sql-server-introduction-to-joins-basic-of-joins/[^]


Hope this will help:


如果您需要从2个表中检索数据,则必须在SQL查询中使用innerjoins,请确保这两个表使用主键相互连接.


您可以在下面的链接中获得有关内部联接的简短介绍.

http://www.w3schools.com/sql/sql_join_inner.asp [
You have to use innerjoins in your SQL query if you need to retrieve data from 2 tables , be sure that these two tables are connected to each other with a primary key.


You can get a brief intro about inner joins in the link below.

http://www.w3schools.com/sql/sql_join_inner.asp[^]


在CheckeChanged事件中,单选按钮,写入这样的查询

In CheckeChanged Event of radio button, Write the query like this

SELECT R.dealer name,R.Mobile,P.address,P.city,price,P.locality FROM registration R INNER JOIN Product P ON R.Id=P.Id




如果您想从两个表中获取数据,则需要加入
请参考以下链接

http://www.w3schools.com/sql/sql_join_inner.asp [ http://msdn.microsoft.com/en-us/library/ms191517%28v = SQL.90%29.aspx [ ^ ]




If u want to get data from two tables you need join
Refer following links

http://www.w3schools.com/sql/sql_join_inner.asp[^]


http://msdn.microsoft.com/en-us/library/ms191517%28v=SQL.90%29.aspx[^]


这篇关于如何一次获取两个表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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