加入数据库 [英] joining the database

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

问题描述

我有两个表名student和studentinfo.
在学生表stuid(主键)的学生姓名中.
在studentinfo stuid(外键)本地地址,永久地址等中.
现在我想做的是,当我打算使用gridview时,我想显示
学生信息表中的学生姓名..比怎么办呢?
请回复.....

i have two table names student and studentinfo.
in student table stuid(primary key) studentname.
in studentinfo stuid(foreign key) local address,permenant address etc..
now what i wanted to do is that when i going for using gridview i wanted to display
student name in student info table.. than how can do this??
pls reply.....

推荐答案

您需要使用联接.它们的工作方式如下:

选择学生姓名,[本地地址],<其他字段=" as =" required =">来自学生内部,在student.stuid = studentinfo.stuid上加入studentinfo

内部联接为您提供两个表中都存在s匹配的记录.如果两个表都可能不匹配,请改用左联接.

当然,如果只有一个学生名映射到每个studentinfo行,那么就需要问一个问题,为什么他们根本不在单独的表中!
You need to use a join. They work like this:

select studentname, [local address], <other fields="" as="" required=""> from student inner join studentinfo on student.stuid = studentinfo.stuid

Inner join gives you records where there is s match in both tables. If there''s a chance of no match in both tables, use a left join instead.

Of course, if there is only ever a single studentname mapped to each studentinfo row, then the question needs to be asked why they are in separate tables at all!!


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

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